Translating EasyLanguage to AFL - in general

I have a bunch of Easy Language code that I want to convert to AFL. Has anyone experience of doing this? Is there for example a cross reference of built in routines? Are some of the routines already converted and the AFL code available?

There are quite a lot of these routines I have to implement or find a corresponding AFL routine for:

Thanks for any help!

1 Like


What I'm especially am looking for is Easy Language built in functions, where there is no code. Example :

Easy Language

Value1 = CountIf(Close > Open, 12);

AFL Sum()

Value1 = Sum(Close > Open, 12);

If EL CountIF does not include "current" bar then

Value1 = Ref(Sum(Close > Open, 12), -1);

Of course you can add operators too like in EL

Value1 = Sum(Close > Open AND V > Ref(V,- 1), 12);

If you need to sum values if condtion is true
Sum() combined with IIf()

Value1 = Sum(IIf(Close > Open, Close, 0), 12);

Thanks again! This is great, it will solve my translation of EL function CountIF. And it opens up some ideas ;0)

In general, is there someone who has done these kind of work on other EL built-in routines?

As mentioned by Tomasz already... it is not difficult and e.g. I have translated several EL to AFL codes already also. What routines/functions have you problems with?

@wmrazek it looks like you have not yet discovered the User Guide and specifically the functions,

I have just started so I cant tell yet, thanks for asking. The EL code is from the book "Professional Stock Trading, System Design and Automation" , by Conway, Behle. They call it Acme Trading System. Its about 70 pages EL code. I can post here next routine I get stuck with ;0)

I'm reading User Guide and AFL Function Reference but I still have lots to learn here. I'm working on it ;0)

1 Like

Ok, I'm stuck on this one:

I probably can code it but I think I will ask here first.

Wrong way around!

Try and code it and if you get stuck then post your full code attempt for assistance.

1 Like

Thanks for your reply, I appreciate it. Just want to clarify, so there is no misunderstanding. I agree, always try first and then ask questions.

That is what "I'm stuck..." means. I have done that. My code so far is nothing to show because it just not make sense. I'm still working on it, for example, using sort(), percentile() but it still not make sense. One of the most basic things in entrepreneurship is to ask questions.

1 Like


I did not manage to code NthLowestBar. So in the EL code where NthLowestBar is used, I use something else.

A short description:
" A TestBar is a bar that breaks previous support or resistance and then rebounds in the other direction. In a bullish TestBar, the bar breaks below a previous low (cannot be the low of one bar ago) and closes in its top half range."

EL code:


AcmeTest = 0;

If Low < Lowest( Low, Length-1)[1] and
NthLowestBar(2, Low, Length) >= SeparationBars and
AcmeRangePercent( Close, 1) > 0.5 Then
AcmeTest = 1;

AFL code:

function NthLV( array, period, nth ) {
    return Percentile( array, period, (nth - 1) / (period - 1) * 100 );

function AcmeTest()
	// local variables
	length = 20;
	previous_1stLowestLow = Ref( NthLV( L, length-1, 1), -1); 
	previous_2ndLowestLow = Ref( NthLV( L, length-1, 2), -1);
		// bar breaks below a previous lowest Low
		L < previous_1stLowestLow
		// the 2nd lowest Low is more than two bars away
		Ref( L, -1) != previous_2ndLowestLow
		Ref( L, -2) != previous_2ndLowestLow
		// Close is in the top half of the range
		AcmeRangePercent( C, 1) > 0.5;

AcmeRangePercent function tells where in the range (H-L) the close is.

Please comment, I appreaciate it. I haven't used AFL for a while so I'm "rusty".

For the function NthLV, see link

NthLV and NthLowestBar differ in their outputs. Both finds lowest, 2nd lowest, 3rd lowest etc but NthLV returns the Low value and NthLowestBar returns the number of bars ago it occured.

You just need to use the function that I wrote previously and check at which bar the NthLow was hit. Below is the formula:

// NthLowest(Bars) AFL code copyright (C)2020 Tomasz Janeczko
// The formula can be used only if copyright notice is retained
// Nth starts from 1, so second lowest is 2

function NthLowest( array, Nth, period )
	return Percentile( array, period, 100 * ( Nth - 1 ) / ( period - 1 ) );

function NthLowestBars( array, Nth, period )
	nlv = Percentile( array, period, 100 * ( Nth - 1 )/ ( period - 1 ) );
	bars = Null;
	for( i = 0; i < period; i++ )
		bars = IIf( Ref( array, -i ) == nlv, i, bars ); 
	return bars;

Filter = 1;
AddColumn( Close, "Close");
AddColumn( LLV( Close, 10 ), "1st Lowest");
AddColumn( LLVBars( Close, 10 ), "1st Lowest bars");
AddColumn( NthLowest( Close, 2, 10 ), "2nd Lowest" );
AddColumn( NthLowestBars( Close, 2, 10 ), "2nd Lowest bars" );

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.