//+------------------------------------------------------------------+ //| ZigZag.mq4 | //| Copyright © 2005, MetaQuotes Software Corp. | //| http://www.metaquotes.net/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2005, MetaQuotes Software Corp." #property link "http://www.metaquotes.net/" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Red //---- indicator parameters extern int ExtDepth=12; extern int ExtDeviation=5; extern int ExtBackstep=3; //---- indicator buffers double ExtMapBuffer[]; double ExtLowBuffer[]; double ExtHighBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { IndicatorBuffers(3); //---- drawing settings SetIndexStyle(0,DRAW_SECTION); //---- indicator buffers mapping SetIndexBuffer(0,ExtMapBuffer); SetIndexBuffer(1,ExtLowBuffer); SetIndexBuffer(2,ExtHighBuffer); SetIndexEmptyValue(0,0.0); //---- indicator short name IndicatorShortName("ZigZag("+ExtDepth+","+ExtDeviation+","+ExtBackstep+")"); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { int shift, back,lasthighpos,lastlowpos,index; double val,res; double curlow,curhigh,lasthigh,lastlow; //---- for(shift=Bars-ExtDepth; shift>=0; shift--) { index=Lowest(NULL,0,MODE_LOW,ExtDepth,shift); val=Low[index]; if(val==lastlow) val=0.0; else { lastlow=val; if((Low[shift]-val)>(ExtDeviation*Point)) val=0.0; else { for(back=1; back<=ExtBackstep; back++) { res=ExtLowBuffer[shift+back]; if((res!=0)&&(res>val)) ExtLowBuffer[shift+back]=0.0; } } } ExtLowBuffer[shift]=0.0; if(val!=0.0) ExtLowBuffer[index]=val; //--- high index=Highest(NULL,0,MODE_HIGH,ExtDepth,shift); val=High[index]; if(val==lasthigh) val=0.0; else { lasthigh=val; if((val-High[shift])>(ExtDeviation*Point)) val=0.0; else { for(back=1; back<=ExtBackstep; back++) { res=ExtHighBuffer[shift+back]; if((res!=0)&&(res=0; shift--) for(shift=Bars-ExtDepth; shift>=start; shift--) { curlow=ExtLowBuffer[shift]; curhigh=ExtHighBuffer[shift]; if(curlow==0 && curhigh==0) continue; //--- if(curhigh!=0) { if(lasthigh>0) { if(lasthigh0) { if(lastlow>curlow) ExtLowBuffer[lastlowpos]=0; else ExtLowBuffer[shift]=0; } //--- if((curlow=0; shift--) for(shift=Bars-1; shift>=start; shift--) { if(shift>=Bars-ExtDepth) ExtMapBuffer[shift]=0.0; else { curlow=ExtLowBuffer[shift]; curhigh=ExtHighBuffer[shift]; //---- res=0; if(curlow!=0) { if(lastlowpos==-1) { res=curlow; lastlowpos=shift; } else { if(lasthighpos!=-1 && lastlowpos>lasthighpos) { res=curlow; lastlowpos=shift; } } } if(curhigh!=0) { if(lasthighpos==-1) { res=curhigh; lasthighpos=shift; } else { if(lastlowpos!=-1 && lasthighpos>lastlowpos) { res=curhigh; lasthighpos=shift; } } } //---- ExtMapBuffer[shift]=res; } } } //+------------------------------------------------------------------+