/*[[ Name := MACO Indicator Author := Shaun Reed Separate Window := Yes First Color := Red First Draw Type := Line First Symbol := 217 Use Second Data := No Second Color := Red Second Draw Type := Line Second Symbol := 218 ]]*/ Inputs : OpenMAPeriod(8), CloseMAPeriod(5); Variables : shift(0), cnt(0), sum(0), loopbegin1(0), loopbegin2(0), first(True), prevbars(0); Variables : OpenMA(0), CloseMA(0), MACOLine(0); SetLoopCount(0); // initial checkings If OpenMAPeriod < 1 Or CloseMAPeriod < 1 Then Exit; // check for additional bars loading or total reloading If Bars < prevbars Or Bars-prevbars>1 Then first = True; prevbars = Bars; // loopbegin1 and loopbegin2 prevent recounting of counted bars and excludes the current bar If first Then Begin loopbegin1 = Bars-OpenMAPeriod-1; If loopbegin1 < 0 Then Exit; // not enough bars for counting loopbegin2 = Bars-CloseMAPeriod-1; If loopbegin2 < 0 Then Exit; // not enough bars for counting first = False; // this block is to be evaluated once only End; // Construct both Price Exponential MAs loopbegin1 = loopbegin1+1; // current bar is to be recounted too For shift = loopbegin1 Downto 0 Begin OpenMA = iMAEx(OpenMAPeriod,MODE_EMA,0,PRICE_OPEN,shift); CloseMA = iMAEx(CloseMAPeriod,MODE_EMA,0,PRICE_CLOSE,shift); MACOLine = CloseMA-OpenMA; SetIndexValue(shift,MACOLine); loopbegin1 = loopbegin1-1; // prevent previous bars from being recounted End;