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