MetaStock -> Tools -> Indicator Builder -> New -> copy & paste all formulae below. =========== Weekly OHLC =========== ---8<--------------------------- { Weekly Open/High/Low/Close v5.0 For daily/intraday charts. Copyright © 2002-2007 Jose Silva. The grant of this license is only for personal use; no re-sale/packaging/distributing allowed. All code remains the property of Jose Silva. http://www.metastocktools.com } { User inputs } pds:=Input("Week's OHLC: [1]Current (dynamic), [2]Previous",1,2,2); EOW:=Input("Final week's end: [1]Current (dynamic), [2]True",1,2,2); plotOp:=Input("plot weekly Open? [1]Yes, [0]No",0,1,1); plotHi:=Input("plot weekly High? [1]Yes, [0]No",0,1,1); plotLo:=Input("plot weekly Low? [1]Yes, [0]No",0,1,1); plotCl:=Input("plot weekly Close? [1]Yes, [0]No",0,1,1); { Calendar counter engine } y:=Year()-(Month()<3); leap:=Int(y/4)-Int(y/100)+Int(y/400); mth:=Int((2+153*(Month()-3+12*(Month()<3)))/5); dayNr:=DayOfMonth()+mth+y*365+leap-730425; WkCount:= Int((DayNr-(If(DayNr<1,1,2)-(Frac(Year()/100)=0 AND Frac(Year()/400)<>0)))/7)+(Year()>=2000); { Week's start signal } WkStart:=WkCount>Ref(WkCount,-1); { Week's end signal } { Choice of Static/Dynamic last EOW signal } EOW:=If(EOW=1,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 } WkEnd:=PeakBars(1,-(If(detect=0, WkStart OR Cum(IsDefined(WkStart))=1, Cum(1)/2=Int(Cum(1)/2))),1)=0 OR EOW; WkEnd:=If(detect=0,WkEnd,1); { 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,WkEnd,Hi)); wkHi:=ValueWhen(1,wkHi<>0,wkHi); { Week's Low } Lo:=LowestSince(1,WkStart,L); wkLo:=If(pds=1,Lo,ValueWhen(1,WkEnd,Lo)); wkLo:=ValueWhen(1,wkLo<>0,wkLo); { Week's Close } wkCl:=If(pds=1,C,ValueWhen(pds,WkEnd,C)); wkCl:=ValueWhen(1,wkCl<>0,wkCl); { Select price plots } wkCl:=If(plotCl,wkCl,C); wkOp:=If(plotOp,wkOp,wkCl); wkHi:=If(plotHi,wkHi,wkCl); wkLo:=If(plotLo,wkLo,wkCl); { Plot price on chart, signals in own window } wkOp; { <- Open: Violet} wkHi; { <- High: Blue } wkLo; { <- Low: Red } wkCl; { <- Close: Green } ---8<--------------------------- ======================= Weekly WC/Typical price ======================= ---8<--------------------------- { Weekly Weighted Close / Typical Price v3.1 For daily/intraday charts. Requires either "Week's true start & end" or "Week's true start & end(2)" indicators. ©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 } plot:=Input("Plot weekly: [1]Weighted Close, [2]Typical Price",1,2,1); pds:=Input("Weekly plot: [1]Current (dynamic), [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 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); { Select price plots } weeklyPlot:=If(plot=1, (wkHi+wkLo+wkCl*2)/4, (wkHi+wkLo+wkCl)/3); { Plot price on chart, signals in own window } weeklyPlot ---8<--------------------------- ======================= 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<--------------------------- ========================= 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<--------------------------- http://www.metastocktools.com