PureBytes Links
Trading Reference Links
|
Karile
> Hi Roy,
>
> For my explorations (daily timeframe), I would like to use a weekly
> moving average (20, simple, close).
>
> Is it possible to do it with Metastock ?
>
> Thanks for your help,
>
> Karile
Yes it's easily enough done. The following SMA is quite accurate but not perfect. The method I'm
using is prone to what I think are "single digit precision" errors. This can mean that an integer
result might plot fractionally off (24.00 may plot as 23.999999). I have in mind a different method
of constructing the indicator but haven't got it to the top of my "to do" list yet.
This code can operate in "dynamic current week" mode. Using this will simulate the current bar of a
weekly periodicy chart but you must remember that this is a dynamic value and will probably change
with Tuesday, Wednesday, Thursday and Friday daily data. Keep this in mind if using it with an
exploration during the week. By all means test it to verify that it is giving accurate values.
Testing can't be done properly on a weekly chart because missing Friday's cause the indicator to
miss a complete bar of data. This problem is fully take care of with daily charts and the weekly
values (on daily charts) will not be affected (other than the data sample being taken one bar later
than ideal) by holidays and the like.
A weekly EMA is shown for good measure.
Roy
{Weekly SMA - Close}
{© 2003 Roy Larsen}
{rlarsen@xxxxxxxxxxxxxx}
{use on daily charts}
D:=Input("Periods in Weeks",1,999,20);
Q:=Input("Dynamic Current Week?",0,1,0);
{0=Update when end of current week is known}
{1=MS compatible dynamic current week}
M:=DayOfWeek()<=ValueWhen(2,1,DayOfWeek());
F:=DayOfWeek()=5;
A:=LastValue(Cum(1)-1)=Cum(1);
B:=LastValue(Cum(1))=Cum(1);
J:=If(F,1,If(Alert(F,2)= 0 AND M,2,0));
J:=If(A+LastValue(J)>2 OR B+Q>1,1,(B=0)*J);
K:=ValueWhen(1,J,If(J=1,C,ValueWhen(2,1,C)));
G:=Cum((J>0)*K);
X:=(G-ValueWhen(D+1,J,G))/D;
X;
{Weekly EMA - Close}
{© 2003 Roy Larsen}
{rlarsen@xxxxxxxxxxxxxx}
{use on daily charts}
D:=Input("Periods in Weeks",1,999,20);
D:=2/(1+D);
Q:=Input("Dynamic Current Week?",0,1,0);
{0=Update when end of current week is known}
{1=MS compatible dynamic current week}
M:=DayOfWeek()<=ValueWhen(2,1,DayOfWeek());
F:=DayOfWeek()=5;
A:=LastValue(Cum(1)-1)=Cum(1);
B:=LastValue(Cum(1))=Cum(1);
J:=If(F,1,If(Alert(F,2)=0 AND M,2,0));
J:=If(A+LastValue(J)>2 OR B+Q>1,1,(B=0)*J);
K:=ValueWhen(1,J,If(J=1,C,ValueWhen(2,1,C)));
X:=If(Cum(J>0)=1,K,ValueWhen(1,J,PREV)*(1-D)+K*D);
X;
To unsubscribe from this group, send an email to:
Metastockusers-unsubscribe@xxxxxxxxxxx
Yahoo! Groups Links
To visit your group on the web, go to:
http://groups.yahoo.com/group/Metastockusers/
To unsubscribe from this group, send an email to:
Metastockusers-unsubscribe@xxxxxxxxxxxxxxx
Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|