/*[[ Name := DiNapoli_MACD_(DEMA) Author := Copyright © 2004, a1cor. Notes := MACD (DEMA) DiNapoli Separate Window := Yes First Color := Red First Draw Type := Line Use Second Data := Yes Second Color := Blue Second Draw Type := Line ]]*/ Inputs : FastMAPeriod(8.3896), SlowMAPeriod(17.5185), SignalMAPeriod(9.0503); Variables : shift(0), loopbegin(0), first(True), prevbars(0); Variables : FastMA(0), SlowMA(0), prev(0); SetLoopCount(0); // initial checkings If FastMAPeriod < 1 Or SlowMAPeriod < 1 Or SignalMAPeriod < 1 Then Exit; If FastMAPeriod >= SlowMAPeriod Then Exit; // check for additional bars loading or total reloading If Bars < prevbars Or Bars-prevbars>1 Then first = True; prevbars = Bars; // loopbegin prevent counting of counted bars exclude current If first Then Begin loopbegin = Bars-SlowMAPeriod-1; If loopbegin < 0 Then Exit; // not enough bars for counting first = False; // this block is to be evaluated once only End; // convergence-divergence & signal line loopbegin = loopbegin+1; // current bar is to be recounted too For shift = loopbegin Downto 0 Begin FastMA = iMAEx(FastMAPeriod,MODE_EMA,0,PRICE_CLOSE,shift); SlowMA = iMAEx(SlowMAPeriod,MODE_EMA,0,PRICE_CLOSE,shift); SetIndexValue(shift,FastMA-SlowMA); prev = GetIndexValue2(shift+1); SetIndexValue2(shift, prev + 2 * (FastMA - SlowMA - prev) / (SignalMAPeriod + 1)); loopbegin = loopbegin-1; // prevent to previous bars recounting End;