/*[[ Name := Average True Range Ratio Author := Damiani Link := Separate Window := yes First Color := lime First Draw Type := Line Use Second Data := yes Second Color:= DimGray Second Draw Type := Line ]]*/ Inputs : Per1(10), Per2(100),horlin(0.65),numbars(1000); Variables : shift(0),atrp(0), atrb(0),atr_ratio(0),sma(0),s1(0),s2(0),s3(0),s4(0),s5(0); Variables : bar(0), prevbars(0), start(0), cs(0), prevcs(0),commodt(0); SetLoopCount(0); cs= Per1+ Per2+numbars; //checksum used to see if parameters have been changed if cs=prevcs and (commodt=symbol) then start=Bars-prevbars //params haven't changed only need to calculate new bar else start=-1; commodt=symbol; prevbars = Bars; prevcs = cs; if (start=1 | start=0) then bar=start else bar=numbars-1; For shift = Bar Downto 0 Begin atrp=iatr(Per1,shift); atrb=iatr(Per2,shift); atr_ratio=atrp/atrb; s1=atr_ratio/5; sma=s1+s2+s3+s4+s5; SetIndexValue(shift,atr_ratio); SetIndexValue2(shift,horlin); s2=s1; s3=s2; s4=s3; s5=s4; End;