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

[EquisMetaStock Group] Re: Improve Moving Average



PureBytes Links

Trading Reference Links

If you can live with an EMA instead of SMA, here is some code that 
does what you want:

===
EMA
===
---8<---------------------------

{ Exponential Moving Average v2.0 }
{ EMA periodicity shortens on low bar count }
{ ©Copyright 2003 Jose Silva }
{ http://users.bigpond.com/prominex/pegasus.htm }

pds:=Input("EMA periods",1,2520,21);
x:=Input("use Open=1 High=2 Low=3 Close=4 Volume=5 P=6",1,6,4);
shift:=1+Input("EMA vertical shift %",
 -100,100,0)/100;
plot:=Input("EMA=1, Crossover signals=2",1,2,1);

x:=If(x=1,O,If(x=2,H,If(x=3,L,If(x=5,V,If(x=6,P,C)))));
pds:=If(pds>Cum(x<>-101),Cum(x<>-101),pds); { <--- ! }
Ema:=x*2/(pds+1)+PREV*(1-2/(pds+1));
Ema:=Ema*shift;
signals:=Cross(x,Ema)+-Cross(Ema,x);

If(plot=2,signals,Ema)

---8<---------------------------


jose '-)


--- In equismetastock@xxxxxxxxxxxxxxx, bellamy_29m@xxxx wrote:
> I am trying to write a MS6.52 formula to handle the situation where 
> there are less data points available than a nominated moving average 
> period, so I want the MA to show for the available data points until 
> there enough data points for the MA to operate normally. (Easily 
done 
> in VB, VBA, C, C++, just not MS!)
> 
> Not knowing exactly how to get around MS lack of flexibility, I was 
> trying:
> 
> prd:=Input("MA Periods...",1,100,5);
> x:=Input("1-Open 2-High 3-Low 4-Close 5-Volume 6-P",1,6,4);
> x:=If(x=1,O,If(x=2,H,If(x=3,L,If(x=5,V,If(x=6,P,C)))));
> ma:=If(Cum(1)<prd,Sum(x,Cum(1))/Cum(1),Mov(x,prd,S));
> ma;
> 
> which didn't work, with the error message "This variable or 
> expression must contain only constant data"
> 
> ... so I then tried to set the prd value using code:
> 
> prd:=Input("MA Periods...",1,100,5);
> prd:=If(Cum(1)<prd,Cum(1),prd);
> x:=Input("1-Open 2-High 3-Low 4-Close 5-Volume 6-P",1,6,4);
> x:=If(x=1,O,If(x=2,H,If(x=3,L,If(x=5,V,If(x=6,P,C)))));
> ma:=Mov(x,prd,S);
> ma;
> 
> which didn't work either, with the same error message "This variable 
> or expression must contain only constant data"
> 
> Hopefully, someone can see what I am trying to achieve and will be 
> able to help.  Any assistance would be greatly appreciated.



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com.  Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/BefplB/TM
---------------------------------------------------------------------~->

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/equismetastock/

<*> To unsubscribe from this group, send an email to:
     equismetastock-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/