/*[[ Name := Awesome Oscillator Author := Copyright © 2004, MetaQuotes Software Corp. Link := http://www.metaquotes.net/ Separate Window := Yes First Color := Blue First Draw Type := Histogram First Symbol := 217 Use Second Data := Yes Second Color := Red Second Draw Type := Histogram Second Symbol := 218 ]]*/ Inputs : FastMAPeriod(5), SlowMAPeriod(34),shift(0); Variables : cnt(0), sum(0), loopbegin(0), first(True), prevbars(0); Variables : FastMA(0), SlowMA(0),FastMA2(0), SlowMA2(0),P(0), P2(0),prevP(0); SetLoopCount(0); // initial checkings If FastMAPeriod < 1 Or SlowMAPeriod < 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 loopbegin = loopbegin+1; // current bar is to be recounted too For shift = loopbegin Downto 0 Begin FastMA = iMAEx(FastMAPeriod,MODE_EMA,0,Close,shift); SlowMA = iMAEx(SlowMAPeriod,MODE_EMA,0,Close,shift); //We need to do it again with a shift back one bar(shift+1) //so we can change colors in the histogram. FastMA2 = iMAEx(FastMAPeriod,MODE_EMA,0,Close,shift+1); SlowMA2 = iMAEx(SlowMAPeriod,MODE_EMA,0,Close,shift+1); P = FastMA-SlowMA; P2 =FastMa2-SlowMA2; //If the current bar is less than the last bar in our histogram we want it to be Red. //If the current bar is greater than the last bar in our histogram we want it to be Green. If P>P2 then SetIndexValue(Shift,P); If P