MetaStock -> Tools -> Indicator Builder -> New -> Copy and paste all formulae below. ======================= Week's true Start & End ======================= ---8<--------------------------- { Week's true start & end of week (EOW) v3.0 Confirms EOW signal at start of following week, and signals EOW in retrospect. For daily & intraday charts. ©Copyright 2002~2006 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 } EOW:=Input("Final week's end: [1]True, [2]Current (dynamic)",1,2,1); adj:=Input("Week's start: [0]Sunday, [1]Monday",0,1,1); { Calendar counter engine } 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)-730484; 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(); adj:=adj+If(DayNr<1,1,2) -(Frac(Year()/100)=0 AND Frac(Year()/400)<>0); WkCount:=Int((DayNr-adj)/7)+(Year()>=2000); { 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<--------------------------- Testing the above indicator to breaking point in highly irregular charts, rare instances have been found where the occasional 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, MetaStockTools.com also offers a custom DLL version of this indicator - it plots EOW signals correctly at all times 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 (frequent missing data) daily & intraday charts. Use v3.0 signals for normal charts. ©Copyright 2002~2006 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 } EOW:=Input("Final week's end: [1]True, [2]Current (dynamic)",1,2,1); adj:=Input("Week's start: [0]Sunday, [1]Monday",0,1,1); { Calendar counter engine } 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)-730484; 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(); adj:=adj+If(DayNr<1,1,2) -(Frac(Year()/100)=0 AND Frac(Year()/400)<>0); WkCount:=Int((DayNr-adj)/7)+(Year()>=2000); { 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<--------------------------- Below is the latest and simplest calendar-based Week-start signals: ================= Week's true Start ================= ---8<--------------------------- d:=Rnd(Life(293112)+DayOfWeek()); d