MetaStock -> Tools -> Indicator Builder -> New -> copy & paste complete formula between "---8<---" lines. ========================= Countback-type Oscillator ========================= ---8<------------------------------------- { Countback-type oscillator & signals v2.0 Incorporating automatic overBought/Sold levels Trade at own risk. ©Copyright 2005~2006 Jose Silva. The grant of this license is for personal use only - no resale or repackaging allowed. http://www.metastocktools.com } { User inputs } pds:=Input("Oscillator countback periods", 1,252,21); plot:=Input("plot: [1]Oscillator, [2]Signals", 1,2,1); type:=Input("signals: [1]OBought/Sold, [2]Higher Lo, Lower Hi",1,2,1); { Countback oscillator } C1:=Ref(C,-1); x:=Sum((C>C1)*(C-C1),pds) /Max(Sum(Abs(C-C1),pds),.000001)*100; { Automatic overBought/Sold levels } avg:=Cum(x)/Cum(IsDefined(x)); pk:=Ref(x,-1)=HHV(x,3) AND Ref(x,-1)>avg; pkVal1:=ValueWhen(1,pk,Ref(x,-1)); pkVal2:=ValueWhen(2,pk,Ref(x,-1)); pkValAvg:=Cum(pkVal1)/Cum(IsDefined(pkVal1)); tr:=Ref(x,-1)=LLV(x,3) AND Ref(x,-1)pkValAvg; { Higher troughs / lower peaks signals } entry:=If(type=1,entry, trVal1>trVal2 AND x>pkVal1); exit:=If(type=1,exit, pkVal10 OR init,entry); long:=bin*(Alert(bin=0,2) OR entry*Cum(entry)=1); short:=(bin=0)*(Alert(bin,2) OR exit*Cum(exit)=1); { Plot in own window } If(plot=1,pkValAvg,0); {Grey} If(plot=1,avg,0); {Grey} If(plot=1,trValAvg,0); {Grey} If(plot=1,x,long-short) ---8<------------------------------------- http://www.metastocktools.com