MetaStock -> Tools -> Indicator Builder -> New -> Copy and paste complete formula between "---8<---" lines. ========== Yearly RoC ========== ---8<----------------------------- { Yearly Rate of Change (RoC) v4.2 Note: First incomplete year plots RoC from 4th bar. 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 } method:=Input("Method: [1]%percent, [2]$points",1,2,1); yr:=Input("RoC for Year [1800~2200]",1800,2200,2007); yrNr:=Input("Yearly RoC: [1]Year, [2]Yearly, [3]Historical",1,3,2); plot:=Input("plot: [1]RoC, [2]Year signals",1,2,1); { Start/End of year } init:=Cum(1)=4; nuYear:=Year()<>Ref(Year(),-1) OR Cum(1)=2; YearEnd:=PeakBars(1,-(nuYear OR Cum(IsDefined(nuYear))=1 OR init),1)=0; { Data Array } x:=C; { Yearly % RoC } chPer:=(x/ValueWhen(1,YearEnd,x)-1)*100; chPer:=If(YearEnd=0,chPer, (x/ValueWhen(2,YearEnd OR init,x)-1)*100); { Yearly $ RoC } chPts:=x-ValueWhen(1,YearEnd,x); chPts:=If(YearEnd=0,chPts, x-ValueWhen(2,YearEnd OR init,x)); { Select %/$ RoC method } ch:=If(method=1,chPer,chPts); { Restrict RoC to selected year } chYear:=If(Year()=yr,ch,0); chYear:=If(Year()=yr,chYear, ValueWhen(1, init OR YearEnd AND Year()=yr,chYear)); { Historical RoC from beginning of chart } chAllPts:=x-ValueWhen(1,Cum(1)=1,x); chAllPer:=(x/ValueWhen(1,Cum(1)=1,x)-1)*100; { Select %/$ historical RoC method } chAll:=If(method=1,chAllPer,chAllPts); { Select type of Yearly RoC } YearRoc:=If(yrNr=1,chYear,If(yrNr=2,ch,chAll)); { Plot in own window } If(plot=1,YearRoc,nuYear-YearEnd) ---8<----------------------------- http://www.metastocktools.com