/*[[ Name := CCI period average Author := Alejandro Galindo Link := Help me to continue coding, PayPal donations to ag@elcactus.com, thanks :) Separate Window := Yes First Color := Yellow First Draw Type := Line Use Second Data := Yes Second Color := Red Second Draw Type := Line Second Symbol := 218 ]]*/ Inputs : PeriodsCCI(14), PeriodstoAvrg(5); Variables : shift(0); Variables : Bar(0), prevbars(0), start(0), cs(0), prevcs(0),n(0),sum(0),commodt(0),CCIAvrg(0); SetLoopCount(0); cs= PeriodsCCI+ PeriodstoAvrg; 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 OR start=0) then Bar=start else Bar=bars-1; For shift = Bar Downto 0 Begin sum = 0; for n = 0 to PeriodstoAvrg -1 begin sum = sum + iCCI(PeriodsCCI,shift+n); end; CCIAvrg = sum/PeriodstoAvrg; SetIndexValue(shift,CCIAvrg); SetIndexValue2(shift,iCCI(PeriodsCCI,shift)); End;