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

[EquisMetaStock Group] Re: Basic components for weekly indicators



PureBytes Links

Trading Reference Links

Testing the weekly EMA to breaking point, Roy Larsen has found a rare 
instance in a highly irregular chart where an End Of Week (EOW) signal 
is missing.

When two or more Start Of Week (SOW) signals follow each other without 
a break in between (e.g., data on a Monday and no other data until the 
following Monday), the EOW signal in between the two SOW signals fails 
to plot.  For this example, the first SOW and EOW signals would be on 
the same bar on that first Monday.

I would strongly advise against trading these kind of illiquid charts 
that may trigger the occasional EOW missing signal.  For those that 
insist on looking at these charts, below is a second version of the 
"Week's true Start & End" indicator that takes care of this problem, 
at the expense of slowing things down with two PREV functions.

For clients that require speedy processing, I also offer a custom DLL 
version of this indicator - it plots EOW signals correctly without the 
use of any PREV functions.


=========================
Week's true Start & End(2)
=========================
---8<---------------------------

{ Week's true start & end of week (EOW) vPREVx2}

{ Confirms EOW signal at start of following
   week, and signals EOW in retrospect.
  Signals independent of any missing chart data.
  For use with highly irregular & sporadic
  (lots of missing data) daily & intraday
   charts.
  Use v2.0 signals for normal (liquid) 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);

{ 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 end signal }
WeekEnd:=LastValue(Ref(WeekStart,1)+PREV-PREV)
 OR EOW;

{ Plot signals in own window }
WeekStart;-WeekEnd

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