# Translating EasyLanguage to AFL - recursivity

Hello,

Probably a noob question, but any help will be appreciated. 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;
Value2 =Value1;
Value3 =.75*(Value1 - Value1) + .25*(Value1 - Value1);
InPhase = .33*Value2 + .67*InPhase;

Plot1(Inphase, "I");

end;

``````

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! @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
``````

Use search before posting.

Your Tradestation code can be translated to single call to IIR function http://www.amibroker.com/f?iir or AMA/AMA2 functions http://www.amibroker.com/f?ama

4 Likes

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
Price = (H+L)/2;
mom = Momentum(Price,6);// Momentum
mom2 = 0.75*Momentum(mom,6) +
0.25*Momentum(Ref(mom,-2),2);
InPhase = AMA(Ref(mom,-3), 0.33);
Your help if very much appreciated. 