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

[EquisMetaStock Group] Weekly MACD for daily & intraday charts



PureBytes Links

Trading Reference Links

And here is weekly MACD & Histogram indicator code for daily & 
intraday charts, based on the new weekly signals code:


====================
Weekly MACD of Close
====================
---8<---------------------------

{ Weekly Close MACD/Signal/Histogram v3.0 }
{ For daily/intraday charts }
{ Requires "Week's true start & end" indicator }

{ ©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);
pds2:=Input("longer weekly EMA periods",
 2,5200,26);
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);

{ Reduce periodicity if insufficient periods }
pds1:=If(pds1>Cum(WkEnd),Cum(WkEnd),pds1);

{ Weekly EMA1 }
WkEma1:=ValueWhen(1,WkEnd,PREV)
 *(1-2/(pds1+1))+WkCl*2/(pds1+1);

{ Weekly EMA2 }
pds2:=If(pds2>Cum(WkEnd),Cum(WkEnd),pds2);
WkEma2:=ValueWhen(1,WkEnd,PREV)
 *(1-2/(pds2+1))+WkCl*2/(pds2+1);

{ 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<---------------------------


jose '-)
http://www.metastocktools.com




--- In equismetastock@xxxxxxxxxxxxxxx, "Jose Silva" <josesilva22@xxxx>
> wrote:
> 
> Programming code to signal the true start of a trading week is 
> relatively easy in MetaStock.
> However, code that signals the true last day of the trading week (or 
> EOW), has been one of MetaStock's Holy Grail.
> 
> The difficulty lies in detecting that last trading day of the week 
> when we all start our weekend a day or more early.
> DayOfWeek()=5 (Friday) does not work when the last day of the week 
> falls on a Thursday, Wednesday (or even Monday & Tuesday with some 
> illiquid securities).
> 
> How is it possible for MetaStock to know about these irregular EOW 
> signals?  Well, with a little hindsight.
> Correct start & end of week signals for daily/intraday charts, 
> independent of any missing chart data:
> 
> 
> MetaStock -> Tools -> Indicator Builder -> New
> -> Copy and paste formula below.
> 
> 
> =======================
> Week's true Start & End
> =======================
> ---8<---------------------------
> 
> { Week's true start & end of week (EOW) v2.0 }
> { Confirms EOW signal at start of following
>    week, and signals EOW in retrospect.}
> { Signals independent of any missing chart data}
> { For daily & intraday charts }
> 
> { ©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 input }
> EOW:=Input("Final week's end:  [1]True,  [2]Current (dynamic)",1,2,
1);
> 
> { Calendar Week counter }
> limit:=2000;  {do not change limit year}
> LimLeap:=Frac(limit/4)=0 AND Frac(limit/100)<>0
>  OR Frac(limit/400)=0;
> NoCount:=limit*365+Int(limit/4)
>  -Int(limit/100)+Int(limit/400)-LimLeap;
> leap:=Frac(Year()/4)=0 AND Frac(Year()/100)<>0
>  OR Frac(Year()/400)=0;
> y:=Year()*365+Int(Year()/4)
>  -Int(Year()/100)+Int(Year()/400)-NoCount;
> m:=
>  If(Month()=2,31-leap,
>  If(Month()=3,59,
>  If(Month()=4,90,
>  If(Month()=5,120,
>  If(Month()=6,151,
>  If(Month()=7,181,
>  If(Month()=8,212,
>  If(Month()=9,243,
>  If(Month()=10,273,
>  If(Month()=11,304,
>  If(Month()=12,334,
>  -leap)))))))))));
> DayNr:=y+m+DayOfMonth();
> WkCount:=Int((DayNr-1)/7)+(Year()>=limit);
> 
> { Week's start signal }
> WeekStart:=WkCount>Ref(WkCount,-1);
> 
> { Week's end signal }
> 
> { Choice of Static/Dynamic last EOW signal }
> EOW:=If(EOW=2,Cum(1)=LastValue(Cum(1)),
>  Cum(1)=LastValue(Cum(1)) AND DayOfWeek()=5);
> 
> { Detect other than daily/intraday charts }
> detect:=LastValue(Cum(
>  WkCount=ValueWhen(2,1,WkCount)))=0;
> 
> { Make EOW signal visible for weekly+ charts }
> WeekEnd:=PeakBars(1,-(If(detect=0,
>   WeekStart OR Cum(IsDefined(WeekStart))=1,
>   Cum(1)/2=Int(Cum(1)/2))),1)=0
>  OR EOW;
> WeekEnd:=If(detect=0,WeekEnd,1);
> 
> { Plot signals in own window }
> WeekStart;-WeekEnd
> 
> ---8<---------------------------
> 
> 
> 
> Now, what's so important about needing to plot accurate start/end of 
> week signals?
> This becomes essential when building weekly indicators for daily & 
> intraday charts - they require accurate start & end-of-week signals.
> The above basic indicator can be easily referenced by other
> MetaStock formulae, making the process of designing weekly
> indicators a lot easier.
> 
> Here is another basic example, weekly Open/High/Low/Close for daily
> & intraday charts:
> 
> 
> ===========
> Weekly OHLC
> ===========
> ---8<---------------------------
> 
> { Weekly OHLC for daily/intraday charts v2.0 }
> { Requires "Week's true start & end" indicator }
> 
> { ©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.
>   josesilva22@xxxx }
> 
> { User inputs }
> pds:=Input("Week's OHLC:  [1]Current,  [2]Previous",1,2,1);
> EOW:=Input("Final week's end:  [1]True,  [2]Current (dynamic)",1,2,
2);
> 
> { Week's true Start }
> WkStart:=
>  FmlVar("Week's true start & end","WEEKSTART");
> 
> { Choice of Static/Dynamic last EOW signal }
> EOW:=If(EOW=2,Cum(1)=LastValue(Cum(1)),
>  Cum(1)=LastValue(Cum(1)) AND DayOfWeek()=5);
> 
> { Week's true End (EOW) }
> WkEnd:=EOW OR
>  FmlVar("Week's true start & end","WEEKEND");
> 
> { Week's Open }
> wkOp:=ValueWhen(pds,WkStart,O);
> wkOp:=ValueWhen(1,wkOp>0,wkOp);
> 
> { Week's High }
> Hi:=HighestSince(1,WkStart,H);
> wkHi:=If(pds=1,Hi,
>  ValueWhen(1,WkStart,Ref(Hi,-1)));
> wkHi:=ValueWhen(1,wkHi>0,wkHi);
> 
> { Week's Low }
> Lo:=LowestSince(1,WkStart,L);
> wkLo:=If(pds=1,Lo,
>  ValueWhen(1,WkStart,Ref(Lo,-1)));
> wkLo:=ValueWhen(1,wkLo>0,wkLo);
> 
> { Week's Close }
> wkCl:=ValueWhen(pds,WkEnd,C);
> wkCl:=ValueWhen(1,wkCl>0,wkCl);
> 
> { Plot on price chart }
> wkOp;wkHi;wkLo;wkCl
> 
> ---8<---------------------------
> 
> Note that with the weekly OHLC indicator, the High/Low of the week
> are always dynamic in the current week, since their values cannot be 
> known until the end of the trading week without cheating Father
> Time...
> 
> 
> With these two basic code components as reference for other code,
> just about any true weekly indicator can be coded in MetaStock (no
> requests please).  :)
> 
> 
> jose '-)
> http://www.metastocktools.com




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Try Online Currency Trading with GFT. Free 50K Demo. Trade 
24 Hours. Commission-Free. 
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/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/