logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
autohm  
#1 Posted : Sunday, September 20, 2009 2:57:22 PM(UTC)
autohm

Rank: Newbie

Groups: Registered, Registered Users
Joined: 9/20/2009(UTC)
Posts: 2

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.
mstt  
#2 Posted : Monday, September 21, 2009 2:39:55 AM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)

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
autohm  
#3 Posted : Thursday, September 24, 2009 5:33:22 PM(UTC)
autohm

Rank: Newbie

Groups: Registered, Registered Users
Joined: 9/20/2009(UTC)
Posts: 2

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!
Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.