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)
|
Ok, this is the latest (and final) version of the Weekly MACD/Histogram, which now also plots MetaStock's default MACD (0.15/0.075):
[code:1:95e5177b45]
====================
Weekly MACD of Close
====================
---8<---------------------------
{ Weekly Close MACD/Signal/Histogram v4.0 }
{ For daily/intraday charts }
{ Requires either "Week's true start & end"
or "Week's true start & end(2)" indicators.}
{ ©Copyright 2002~2005 Jose Silva
The grant of this license is for personal use
only - no resale or repackaging allowed.
All code remains the property of Jose Silva.
http://www.metastocktools.com }
{ User inputs }
pds1:=Input("shorter weekly EMA periods",
1,520,12.3);
pds2:=Input("longer weekly EMA periods",
2,5200,25.7);
pds3:=Input("weekly MACD signal periods",
1,520,9);
EOW:=Input("Final week's end: [1]True, [2]Current (dynamic)",1,2,2);
plot:=Input("plot: [1]MACD, [2]Histogram",
1,2,1);
{ Choice of Static/Dynamic last EOW signal }
EOW:=If(EOW=2,Cum(1)=LastValue(Cum(1)),
Cum(1)=LastValue(Cum(1)) AND DayOfWeek()=5);
{ Reference EOW signals }
WkEnd:=EOW OR
FmlVar("Week's true Start & End","WEEKEND");
{ Week's Close }
WkCl:=ValueWhen(1,WkEnd,C);
WkCl:=ValueWhen(1,WkCl>0,WkCl);
{ Weekly EMA1 }
x:=If(pds1=12.3,0.15,2/(pds1+1));
x:=If(pds1>Cum(1),2/(Cum(WkEnd)+1),x);
WkEma1:=ValueWhen(1,WkEnd,PREV)*(1-x)+WkCl*x;
{ Weekly EMA2 }
x:=If(pds2=25.7,0.075,2/(pds2+1));
x:=If(pds2>Cum(1),2/(Cum(WkEnd)+1),x);
WkEma2:=ValueWhen(1,WkEnd,PREV)*(1-x)+WkCl*x;
{ MACD }
Mac:=WkEma1-WkEma2;
{ Signal }
pds3:=If(pds3>Cum(WkEnd),Cum(WkEnd),pds3);
Signal:=ValueWhen(1,WkEnd,PREV)
*(1-2/(pds3+1))+Mac*2/(pds3+1);
{ Histogram }
Hist:=Mac-Signal;
{ Plot in own window }
If(plot=1,Signal,Hist);
If(plot=1,Mac,0)
---8<---------------------------
[/code:1:95e5177b45]
jose '-)
http://www.metastocktools.com
|