/*[[ Name := choppy market index Author := Copyright © 2004, Nick Bilak Link := Separate Window := Yes First Color := Red First Draw Type := Line Use Second Data := Yes Second Color := DimGray Second Draw Type := Line Second Symbol := 218 ]]*/ Inputs : cperiod(30),trigger(20); Variables : shift(0), loopbegin(0), first(True), prevbars(0); Variables : MAValue(0); SetLoopCount(0); // initial checkings // check for additional bars loading or total reloading If Bars < prevbars Or Bars-prevbars>1 Then first = True; prevbars = Bars; If first Then Begin // loopbegin prevent couning of counted bars exclude current loopbegin = Bars-cperiod-1; If loopbegin < 0 Then Exit; // not enough bars for counting first = False; End; // moving average loopbegin = loopbegin+1; // current bar is to be recounted too For shift = loopbegin Downto 0 Begin MAValue = (Abs(Close[shift] - Close[shift+cperiod])/(HIGH[Highest(MODE_High,shift+cperiod,cperiod)] - LOW[Lowest(MODE_Low,shift+cperiod,cperiod)])*100); SetIndexValue(shift,MAValue); SetIndexValue2(shift,Trigger); loopbegin = loopbegin-1; // prevent to previous bars recounting End;