Fibo ZigZag Indicator For MT5
Table Of Contents:
- Fibo ZigZag Indicator For MT5
- Installing the Fibo ZigZag Indicator For MT5
- Parameters of the Fibo ZigZag Indicator For MT5
- Buffers of the Fibo ZigZag Indicator For MT5
- Main Parts Of The Code
The Fibo ZigZag Indicator For MT5 draws the zigzag on the chart and calculates the fibonacci retracement levels between two subsequent zigzag extreme points. The zigzag can be used for defining the direction of the trend. The fibonacci retracement levels can be used to enter during a pullback. You can configure the indicator with the parameters ExtDepth, ExtDeviation and InpBackstep.
Installing the Fibo ZigZag Indicator For MT5
After you downloaded the indicator via the form above you need to unzip the zip-file. Then you need to copy the file ZigZag.mq5 into the folder MQL5\Indicators of your MT5 installation. After that please restart MT5 and then you will be able to see the indicator in the list of indicators.
Parameters of the Fibo ZigZag Indicator For MT5
The Fibo ZigZag Indicator For MT5 has 3 parameters to configure.
input int ExtDepth=12; input int ExtDeviation = 5; input int ExtBackstep = 3;
Buffers of the Fibo ZigZag Indicator For MT5
The Fibo ZigZag Indicator For MT5 provides 9 buffers.
SetIndexBuffer(0,ZigzagBuffer,INDICATOR_DATA); SetIndexBuffer(1,SignalLongBuffer,INDICATOR_DATA); SetIndexBuffer(2,SignalShortBuffer,INDICATOR_DATA); SetIndexBuffer(3,Level236,INDICATOR_DATA); SetIndexBuffer(4,Level382,INDICATOR_DATA); SetIndexBuffer(5,Level500,INDICATOR_DATA); SetIndexBuffer(6,Level618,INDICATOR_DATA); SetIndexBuffer(7,HighMapBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(8,LowMapBuffer,INDICATOR_CALCULATIONS);
Main Parts Of The Code
int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { int i=0; int limit = 0, counterZ = 0, whatlookfor = 0; int shift = 0, back = 0, lasthighpos = 0, lastlowpos = 0; double val= 0,res = 0; double curlow=0,curhigh=0,lasthigh=0,lastlow=0; static double lastSignalHigh,lastSignalLow; //--- auxiliary enumeration enum looling_for { Pike = 1, // searching for next high Sill = -1 // searching for next low }; //--- initializing if(prev_calculated==0) { ArrayInitialize(ZigzagBuffer,0.0); ArrayInitialize(SignalLongBuffer,0.0); ArrayInitialize(SignalShortBuffer,0.0); ArrayInitialize(Level236, 0.0); ArrayInitialize(Level382, 0.0); ArrayInitialize(Level500, 0.0); ArrayInitialize(Level618, 0.0); ArrayInitialize(HighMapBuffer,0.0); ArrayInitialize(LowMapBuffer, 0.0); } //--- if(rates_total lt 100) return(0); //--- set start position for calculations if(prev_calculated==0) limit=ExtDepth; //--- ZigZag was already counted before if(prev_calculated gt 0) { i=rates_total-1; //--- searching third extremum from the last uncompleted bar while(counterZ lt level && i gt rates_total-100) { res=ZigzagBuffer[i]; if(res!=0) counterZ++; i--; } i++; limit=i; //--- what type of exremum we are going to find if(LowMapBuffer[i]!=0) { curlow=LowMapBuffer[i]; whatlookfor=Pike; } else { curhigh=HighMapBuffer[i]; whatlookfor=Sill; } //--- chipping for(i=limit+1; i lt rates_total && !IsStopped(); i++) { ZigzagBuffer[i] = 0.0; LowMapBuffer[i] = 0.0; HighMapBuffer[i]= 0.0; } } //--- searching High and Low for(shift=limit; shift lt rates_total && !IsStopped(); shift++) { val=low[iLowest(low,ExtDepth,shift)]; if(val==lastlow) val=0.0; else { lastlow=val; if((low[shift]-val) gt deviation) val=0.0; else { for(back=1; back lt =ExtBackstep; back++) { res=LowMapBuffer[shift-back]; if((res!=0) && (res gt val)) LowMapBuffer[shift-back]=0.0; } } } if(low[shift]==val) LowMapBuffer[shift]=val; else LowMapBuffer[shift]=0.0; //--- high val=high[iHighest(high,ExtDepth,shift)]; if(val==lasthigh) val=0.0; else { lasthigh=val; if((val-high[shift]) gt deviation) val=0.0; else { for(back=1; back lt =ExtBackstep; back++) { res=HighMapBuffer[shift-back]; if((res!=0) && (res lt val)) HighMapBuffer[shift-back]=0.0; } } } if(high[shift]==val) HighMapBuffer[shift]=val; else HighMapBuffer[shift]=0.0; } //--- last preparation if(whatlookfor==0) { // uncertain quantity lastlow=0; lasthigh=0; } else { lastlow=curlow; lasthigh=curhigh; } //--- final rejection for(shift=limit;shift lt rates_total && !IsStopped(); shift++) { res=0.0; switch(whatlookfor) { case 0: // search for peak or lawn if(lastlow==0 && lasthigh==0) { if(HighMapBuffer[shift]!=0) { lasthigh=high[shift]; lasthighpos = shift; whatlookfor = Sill; ZigzagBuffer[shift]=lasthigh; res=1; } if(LowMapBuffer[shift]!=0) { lastlow=low[shift]; lastlowpos=shift; whatlookfor=Pike; ZigzagBuffer[shift]=lastlow; res=1; } } break; case Pike: // search for peak if(LowMapBuffer[shift]!=0.0 && LowMapBuffer[shift] lt lastlow && HighMapBuffer[shift]==0.0) { ZigzagBuffer[lastlowpos]=0.0; lastlowpos=shift; lastlow=LowMapBuffer[shift]; ZigzagBuffer[shift]=lastlow; res=1; } if(HighMapBuffer[shift]!=0.0 && LowMapBuffer[shift]==0.0) { lasthigh=HighMapBuffer[shift]; lasthighpos=shift; ZigzagBuffer[shift]=lasthigh; whatlookfor=Sill; res=1; //--- Fibo levels build low if(lastlow!=lastSignalLow) { if(lasthigh) { Level236[shift] = lastlow - getFiboLevel(lastSignalHigh, lastlow, 0.236); Level382[shift] = lastlow - getFiboLevel(lastSignalHigh, lastlow, 0.382); Level500[shift] = lastlow - getFiboLevel(lastSignalHigh, lastlow, 0.500); Level618[shift] = lastlow - getFiboLevel(lastSignalHigh, lastlow, 0.618); } lastSignalLow=SignalShortBuffer[shift]=lastlow; } } break; case Sill: // search for lawn if(HighMapBuffer[shift]!=0.0 && HighMapBuffer[shift] gt lasthigh && LowMapBuffer[shift]==0.0) { ZigzagBuffer[lasthighpos]=0.0; lasthighpos=shift; lasthigh=HighMapBuffer[shift]; ZigzagBuffer[shift]=lasthigh; } if(LowMapBuffer[shift]!=0.0 && HighMapBuffer[shift]==0.0) { lastlow=LowMapBuffer[shift]; lastlowpos=shift; ZigzagBuffer[shift]=lastlow; whatlookfor=Pike; //--- Fibo levels build high if(lastlow && lasthigh!=lastSignalHigh) { if(lastlow) { Level236[shift] = lasthigh + getFiboLevel(lasthigh, lastSignalLow, 0.236); Level382[shift] = lasthigh + getFiboLevel(lasthigh, lastSignalLow, 0.382); Level500[shift] = lasthigh + getFiboLevel(lasthigh, lastSignalLow, 0.500); Level618[shift] = lasthigh + getFiboLevel(lasthigh, lastSignalLow, 0.618); } lastSignalHigh=SignalLongBuffer[shift]=lasthigh; } } break; default: return(rates_total); } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| Calculate fibo-levels | //+------------------------------------------------------------------+ double getFiboLevel(double high,double low,double fibo) { double range=(high-low)*fibo; return NormalizeDouble(range, Digits()); } //+------------------------------------------------------------------+