Rank: Advanced Member
Groups: Registered, Registered Users Joined: 1/19/2005(UTC) Posts: 1,065 Location: Koh Pha-Ngan, Earth
Was thanked: 2 time(s) in 2 post(s)
|
wabbit wrote:Why does MS not plot the EMA in the first 'x' bars? It has to calculate the values, so why aren't these available to be plotted?
wabbit :D
The only way around the null plot on the 'x' bars of any indicator, is to shorten x periodicity on the initial low/invalid bar count.
Here is an example:
MetaStock -> Tools -> Indicator Builder -> New -> Copy and paste formula below.
[code:1:90aaf480aa]
===
EMA
===
---8<---------------------------
{ Exponential Moving Average v2.2 }
{ EMA periodicity shortens on low bar count }
{ Copyright (c)2003-2005 Jose Silva }
{ http://www.metastocktools.com }
{ User inputs }
pds:=Input("EMA periods",1,2520,21);
x:=Input("use Open=1 High=2 Low=3 Close=4 WClose=5 P=6",1,6,4);
shift:=Input("EMA vertical shift %",
-100,100,0)/100+1;
plot:=Input("[1]EMA, [2]Crossover signals",
1,2,1);
{ Choose data array }
x:=If(x=1,O,If(x=2,H,If(x=3,L,If(x=5,WC(),If(x=6,P,C)))));
{ Shorten periodicity on initial low bar count }
pds:=If(pds>Cum(IsDefined(x)),
Cum(IsDefined(x)),pds);
{ Exponential Mov Avg }
Ema:=x*2/(pds+1)+PREV*(1-2/(pds+1));
{ EMA vertical shift }
Ema:=Ema*shift;
{ EMA crossover signals }
signals:=Cross(x,Ema)-Cross(Ema,x);
{ Plot EMA on price chart }
If(plot=2,signals,Ema)
---8<---------------------------
[/code:1:90aaf480aa]
jose '-)
http://www.metastocktools.com
|