/*[[ Name := ZigZag Author := Copyright © 2003, MetaQuotes Software Corp. Link := http://www.metaquotes.ru Separate Window := YES First Color := Blue First Draw Type := Line Use Second Data := No ]]*/ Inputs: depth(100),deviation(0),backstep(3); Variables : shift(0),lasthigh(-1),lastlow(-1),lasthighpos(0),lastlowpos(0); Variables : val(0),back(0),res(0); Variables : curlow(0),curhigh(0); SetLoopCount(0); lasthigh=-1; lastlow=-1; for shift = Bars-300 downto 0 { //--- low val=Low[Lowest(MODE_LOW,shift+depth-1,depth)]; if val==lastlow then val=0 else { lastlow=val; if (Low[shift]-val)>(deviation*Point) then val=0 else { for back=1 to backstep { res=GetIndexValue(shift+back); if res!=0 and res>val then SetIndexValue(shift+back,0); }; }; }; SetIndexValue(shift,val); //--- high val=High[Highest(MODE_HIGH,shift+depth-1,depth)]; if val==lasthigh then val=0 else { lasthigh=val; if (val-High[shift])>(deviation*Point) then val=0 else { for back=1 to backstep { res=GetIndexValue2(shift+back); if res!=0 and res0 then { if lasthigh0 then { if lastlow>curlow then SetIndexValue(lastlowpos,0) else SetIndexValue(shift,0); }; //--- if curlow