Problem in using ZigZag indicator in MQL 5

 

Hi all I am using ZigZag cator in MQL 5 EA. I have experience that some time CoppyBuffer is giving values and suddenly starts giving 0.00 and again started giving some value and keep on doing this..

Can some body explains why it is happening. and how to handle it.


thanks.

 
salirazataqvi:

Hi all I am using ZigZag cator in MQL 5 EA. I have experience that some time CoppyBuffer is giving values and suddenly starts giving 0.00 and again started giving some value and keep on doing this..

Can some body explains why it is happening. and how to handle it.


thanks.

what is the buffer no. you used..
If you use buffer num for Highs it will only show a value for candles with highs, for lows it will be 0.0 or EMPTY_VALUE

But anyway, show the code if this doesn't help..

 
pipspider:

what is the buffer no. you used..
If you use buffer num for Highs it will only show a value for candles with highs, for lows it will be 0.0 or EMPTY_VALUE

But anyway, show the code if this doesn't help..

Thanks pipspider, I got it. I found that some times both buffers are contains 0.0 and some times both contains some other value (same value).


More over please tell me does ZigZag indicator contains only two buffers or it contains other buffers as well?

 
salirazataqvi: 


More over please tell me does ZigZag indicator contains only two buffers or it contains other buffers as well?


You can attach it to a chart and watch the data window on MT5 - it will show all the available buffers there.

 
salirazataqvi:

Thanks pipspider, I got it. I found that some times both buffers are contains 0.0 and some times both contains some other value (same value).


More over please tell me does ZigZag indicator contains only two buffers or it contains other buffers as well?

The original ZigZag indicator contains only one buffer. The buffer contains non-zero values only when there is a certain high or low made by the zigzag line.

So to find the non-zero values in the buffer, we have to find the last high or low made by the zigzag line. 

You can use the following function to do that:

*** Retrieve zigzag highs/lows value

double ZZPeak(int shift) {
   bool signal=false;
   double gd_result=0;
   double gd_peak[]; ArrayResize(gd_peak,shift+1); ArrayInitialize(gd_peak,0);
      int found=0; int c=0;
      while(found<shift+1){ 
         double zig=zigzag_array[c]; // icustom if working in MQl4.
         if(zig!=EMPTY_VALUE &&  zig!=0) { gd_peak[found] = zig; found++; }
         c++;
      }
return(NormalizeDouble(gd_peak[shift],5));
}
Reason: