in Search

Exponential Moving Average (EMA) 9 periods - Initial Value

Last post 09-24-2009, 17:33 by autohm. 2 replies.
Sort Posts: Previous Next
  •  09-20-2009, 14:57 30773

    Exponential Moving Average (EMA) 9 periods - Initial Value

    Greetings,

    I'm trying to work out how Metastock calculates an Exponential Moving Average (EMA) for 9 periods, in particular I'd like to know what it uses as initial value when calculating the first EMA (or what it uses as the first period previous EMA). When I calculate the values outside Metastock I get different results and I'd like to find out why.

    I'm used to using a Simple Moving Average (SMA) as initial value for the EMA, but it seems Metastock does not work that way and I cannot figure how it does.

    When I use formulas (outside Metastock), for instance to calculate EMA(9), I calculate a SMA up to period 9, and then, from period 10 onwards, I'd use the following:

    EMA(current) = (( Price(current) - EMA(prev)) x 0.2) + EMA(prev)

    I get the same results from Metastock if I manually use the first value calculated by Metastock for the EMA, instead of using the SMA. That makes me believe the only difference is indeed in the first value.

    Does anybody know how exacly Metastock calculates it?

    I'd appreciate any help.

    Thanks in advance.




  •  09-21-2009, 2:39 30780 in reply to 30773

    Re: Exponential Moving Average (EMA) 9 periods - Initial Value

    Hi autohm

     

    I believe the following formula is the way that MetaStock generates an EMA. The trick here is the seeding value of C (or whatever data array you wish to smooth) being used to start things off at bar 1. The only difference with this is that the MetaStock Mov() function will artificially suppress a plot until Period bars into the chart – i.e. a 9 period EMA will be suppressed until the ninth bar even though a plot is possible. Since an EMA is determined by the amount of new data included on each new bar (or old data excluded if you wish to put it that way) the result is accurate from bar 2 onward.

     

    Pds:=Input("Periods",1,100,9);

    Rate:=2 / (Pds+1);

    M:=If(Cum(1)=1, C, PREV*(1-Rate) + C*Rate );

    M;

     

    Now you could inhibit the plot until bar 9 simply with the use of a ValueWhen() function.

     

    Pds:=Input("Periods",1,1000,10);

    Rate:=2 / (Pds+1);

    M:=If(Cum(1)=1, C, PREV*(1-Rate) + C*Rate );

    ValueWhen(1,Cum(1)>=Pds,M);

     

    Wilders Smoothing, which is also a form of exponential moving average, does in fact use a simple moving average for seeding on the Periods bar (bar 9).

     

    {Wilders Smoothing}

    Pds:=Input("Periods",1,100,9); 

    Rate:=1/Pds;

    N:=If(Cum(1)<=Pds,Mov(C,Pds,S),PREV*(1-Rate)+C*Rate);

    M;

     

    Hope this helps.

     

    Roy
  •  09-24-2009, 17:33 30827 in reply to 30780

    Re: Exponential Moving Average (EMA) 9 periods - Initial Value

    hi mstt,

    thank you so much for your help.

    indeed you are right, it does supress the plotting until the ninth bar, however, also as you pointed out, it already uses the EMA formula since the second bar and the closing price for the first bar.

    now my results match! thank you once again!
View as RSS news feed in XML