Translating EasyLanguage to AFL - recursivity


Probably a noob question, but any help will be appreciated. :slight_smile:
I'm trying to translate some simple Easy Language code into AFL, but I think I'm having issues with recursivity and initial conditions. I have read other posts on this matter, and I understand that AFL computes everything in an array in 1 pass, with no "current bar" concept (unless you use a for loop).

Here's the Easy Language code source:

Inputs:	Price((H+L)/2);

Vars:	InPhase(0),

If CurrentBar > 5 then begin

	Value1 = Price - Price[6];
	Value2 =Value1[3];
	Value3 =.75*(Value1 - Value1[6]) + .25*(Value1[2] - Value1[4]); 	
	InPhase = .33*Value2 + .67*InPhase[1];
	Quadrature = .2*Value3 + .8*Quadrature[1]; 

	Plot1(Inphase, "I");
	Plot2(Quadrature, "Q");


I first translated the recursive code like this:

Quadrature = 0.2*Value3 + 0.8*Ref(Quadrature,-1);

But my results were very different than the ones I got with the Multicharts trial version.
After reading some posts here, I found that my code wasn't recursive and I was just filling Quadrature will the contents of 0.2*VAlue3 + 0

I understand I would probably have to use the SUM function, but I don't know how exactly. Could someone please give me a hint to put me in the right track? I guess there is a way to do this without using for... loops.

Many thanks in advance! :slight_smile:

@jpeirano, have you tried translating any of the other lines?

On quick look, I don't think it should be too difficult.

Try converting a line at a time and see what you get.

Good job posting your work, but if you try a bit harder you might just surprise yourself.

Your Ref() code is incorrect. Correct code uses AMA/AMA2

Quadrature = AMA( Value3, 0.2 ); // that does 0.2 * Value3 + (1-0.2) * Previous

or using AMA2:

Quadrature = AMA2( Value3, 0.2, 0.8 ); // that does 0.2 * Value3 + 0.8 * Previous

Your question is already answered here: Doubt when using self referencing

Use search before posting.

Your Tradestation code can be translated to single call to IIR function or AMA/AMA2 functions


As been mentioned in thread it is mostly AMA* code.
Here is possible translation of post#1

function Momentum(array, period) {
	// From Charts - Indicators
	return array-Ref(array,-period);

/// EL to AFL translation
/// @link
Price = (H+L)/2;
mom = Momentum(Price,6);// Momentum
mom2 = 0.75*Momentum(mom,6) + 
InPhase = AMA(Ref(mom,-3), 0.33);
Quadrature = AMA(mom2,0.2); 

Plot(Inphase, "I", colorOrange);
Plot(Quadrature, "Q", colorRed);
PlotGrid(0, colorGold);

Many thanks to all!

Your help if very much appreciated. :slight_smile: