MetaStock -> Tools -> Indicator Builder -> New -> copy & paste complete formulae below. ================================== Periodicity marker and OHLC values ================================== ---8<------------------------------- { Signals Nth bar periodicity - v2.2 ©Copyright 2004~2007 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 } pds:=Input("Nth bar periodicity",1,252,21); plot:=Input("plot: [1]Signals, [2]OHLC", 1,2,1); { Nth bar signals } signal:=Mod(Cum(1),pds)=0; { Nth bar OHLC values } Op:=ValueWhen(1,signal,O); Hi:=HighestSince(1,signal,H); Lo:=LowestSince(1,signal,L); Cl:=ValueWhen(1,signal,Ref(C,-1)); { Plot signals in own window; plot OHLC values on chart } If(plot=1,0,Op); { Green } If(plot=1,0,Hi); { Blue } If(plot=1,0,Lo); { Red } If(plot=1,signal,Cl) { Black } ---8<------------------------------- ========================= OHLC at variable interval ========================= ---8<------------------------------ { OHLC at variable period intervals v2.0 ©Copyright 2005-2007 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 } pds:=Input("End-Of-Period (EOP) bar interval", 1,2600,5); type:=Input("EOP signal: [1]Static, [2]Dynamic",1,2,1); plot:=Input("plot: [1]OHLC, [2]EOP signals", 1,2,1); { Static - count bars forward from first bar } countForward:=Cum(1); { Dynamic - count bars back from last bar } countBackward:=LastValue(Cum(1))-Cum(1)+1; { Choose Dynamic/Static } count:=If(type=1,countForward,countBackward); { Signal at x period intervals } signal:=count/pds=Int(count/pds); { OHLC values at x period intervals } Op:=ValueWhen(1,signal,Ref(O,-pds)); Op:=ValueWhen(1,Op<>0,Op); Hi:=ValueWhen(1,signal,Ref(HHV(H,pds),-1)); Hi:=ValueWhen(1,Hi<>0,Hi); Lo:=ValueWhen(1,signal,Ref(LLV(L,pds),-1)); Lo:=ValueWhen(1,Lo<>0,Lo); Cl:=ValueWhen(1,signal,Ref(C,-1)); Cl:=ValueWhen(1,Cl<>0,Cl); { Plot on price charts } If(plot=1,Op,signal); If(plot=1,Hi,signal); If(plot=1,Lo,signal); If(plot=1,Cl,signal) ---8<------------------------------ ================== Periodicity marker ================== ---8<--------------------------- { Periodicity marker v1.2 Signals start of Day/Week/Month/Quarter/Year. ©Copyright 2002~2007 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 } size:=Input("Year-->Day signal increase [100%=all same]",0,100,75)/100; adj:=Input("Week's start: [0]Sunday, [1]Monday",0,1,1); { Message } message:=Input("Plot as histogram in own narrow window below chart",0,0,0); { 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); { Year markers } Yr:=Year()>Ref(Year(),-1); { Quarter markers } m:=Month(); q:=(m<4)+(m>3 AND m<7)*2 +(m>6 AND m<10)*3+(m>9)*4; Qtr:=(q<>Ref(q,-1))*size; { Month markers } size:=size*size; Mth:=(m<>Ref(m,-1))*size; { Week markers } size:=size*size; Week:=(WkCount>Ref(WkCount,-1))*size; { Day markers } Day:=(DayNr>Ref(DayNr,-1))*size*size; { Plot markers as histogram in own window } Day;Week;Mth;Qtr;Yr ---8<--------------------------- Sample application ------------------ ====================== SMA - variable Nth bar ====================== ---8<---------------------------------------- { Variable Nth bar Simple Moving Average v1.0 ©Copyright 2007 Jose Silva. The grant of this license is for personal use only - no resale or repackaging allowed. http://www.metastocktools.com } { User inputs } pds1:=Input("Average Close in every Nth bar",1,260,5); pds2:=Input("SMA periods",1,520,4); shift:=1+Input("SMA vertical shift %", -100,100,0)/100; plot:=Input("[1]SMA, [2]Nth bar, [3]Crossover signals",1,3,1); { Nth bar signals } NthBar:=Mod(Cum(1),pds1)=0; { Nth bar's Close } NthCl:=ValueWhen(1,NthBar,C); NthCl:=ValueWhen(1,NthCl<>0,NthCl); { Nth-bar SMA } z:=Cum(NthBar*NthCl); NthSma:=(z-ValueWhen(pds2+1,NthBar,z))/pds2; { Vertical shift } NthSma:=NthSma*shift; { Crossover signals } signals:=Cross(C,NthSma)-Cross(NthSma,C); { Plot SMA on price chart } If(plot=1,NthSma,If(plot=2,NthBar,signals)) ---8<---------------------------------------- http://www.metastocktools.com