[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: your EMA code



PureBytes Links

Trading Reference Links

At 1:10 PM -0800 3/8/02, Alex Matulich wrote:

>You're welcome.  Basically, any TS function that refers to a
>previous value of its own output (like xAverage does) should be
>re-written so that you have to pass the previous value into the
>function yourself.

Actually, you do not need to pass the previous value as an input
since variables retain their values from bar to bar.

If you want to change the value of "Length" from bar to bar, the key
is to recalculate the factor "w" on each bar rather than only on
CurrentBar = 1 as the Omega function does.

The following code should also work.

Bob Fulks

----


{Function EMA2 - Exponental Moving Average}

Inputs: Price(NumericSimple), Length(NumericSimple);
Variables: w(0), Ave(Price);
w = 2 / (Length + 1);
Ave = w * Price + (1 - w) * Ave;
EMA2 = Ave;