/*[[ Name := ew2 Author := CONVERT BY ENG.AED AL NAIRAB . Link := http://www.nairab.com/ Separate Window := Yes First Color := Blue First Draw Type := Line First Symbol := 217 Use Second Data := No Second Color := Red Second Draw Type := Line Second Symbol := 218 ]]*/ Variable : shift(0),i(0), mean(0), osc(0), wave(0), hiosc(-999), hiosc2(-999), hiprice(-999), hiprice2(-999),hv(0); Array:ET[900](0); SetLoopCount(0); // loop from first bar to current bar (with shift=0) For shift=Bars-1 Downto 0 Begin mean = (high[shift] + low[shift])/2; hv = (high[shift] + low[shift])/2; for i=shift to shift+5 Begin hv=max((high[i] + low[i])/2,hv); end; //Is the current wave sequence up or down? ET[shift] = iCustom("ew1",MODE_FIRST,shift); osc=(iMAEx(5,MODE_SMA,0,PRICE_MEDIAN,shift)-iMAEx(35,MODE_SMA,0,PRICE_MEDIAN,shift)); //When the trend changes from down to up, label it wave 3 and save the current osc and price if (ET[shift] = 1 and ET[shift+1] = -1 and osc > 0 ) then { hiosc = osc; hiprice = mean; wave = 3; }; //If wave 3 and the oscillator make new highs then save those values if wave = 3 then { if mean > hiprice then hiprice = mean; if osc > hiosc then hiosc = osc; }; //Test for the beginning of wave 4 if (osc <= 0 and ET[shift] = 1) then wave = 4; //Test for the beginning of wave 5 if (wave = 4 and mean = hv and osc >= 0 )then { wave = 5; hiosc2 = osc; hiprice2 = mean; }; if wave = 5 then { if osc > hiosc2 then hiosc2 = osc; if mean > hiprice2 then hiprice2 = mean; }; //Test for wave 5 becoming wave 3 if (wave = 5 and hiosc2 > hiosc and ET[shift] = 1) then { wave = 3; hiosc = hiosc2; hiprice = hiprice2; hiosc2 = -999; hiprice2 = -999; }; //Identify a wave 3 down while in wave 5 if (wave = 5 and ET[shift]= -1) then { wave = 3; hiosc = -999; hiprice = -999; hiosc2 = -999; hiprice2 = -999; }; SetIndexValue(shift, wave); End;