Problems on Detecting the peaks and troughs via icustom and the zigzag indicator.

 
Dear all,
  The code attached is  used to detect the number of peaks and troughs in the current chart(the chart I used the EURUSD of period 1 hour) . But the scripts always alerts "0  peaks and 0 troughs" at the end of the script while I can clearly see the peaks and trough on the chart detected by the zigzag indicator. Could someone figure out what is the problem with hte code or how should tackle this issue?
  
//+------------------------------------------------------------------+
//|                                          test custom zigzag .mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#include <objutilities.mqh>

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start(){
  int PeakPointCount=0,TroughPointCount=0;
  string sym;
  int tf;
  double zz=0.0, PeakPointValue=0.0, TroughPointValue=0.0;
  sym=Symbol();
  tf=Period();
    
  for(int i=0;i<Bars;i++){
    string stime;

    //to detect and alert when a peak is detected
    PeakPointValue=0.0;
    PeakPointValue= iCustom(sym,tf,"zigzag",12,5,3,MODE_HIGH,i);
    if (PeakPointValue==iHigh(sym,tf,i)){
      stime=TimeToStr(iTime(sym,tf,i),TIME_DATE|TIME_SECONDS);
      //Alert("i=",i,"PeakPointValue=",DoubleToStr(PeakPointValue,6),", Time=",stime);
      PeakPointCount++;
    }

    //to detect and alert when a trough is detected
    TroughPointValue=0.0;
    TroughPointValue= iCustom(sym,tf,"zigzag",12,5,3,MODE_LOW,i);
    if (TroughPointValue==iLow(sym,tf,i)){
      stime=TimeToStr(iTime(sym,tf,i),TIME_DATE|TIME_SECONDS);
      //Alert("i=",i,"TroughPointValue=",DoubleToStr(TroughPointValue,6),", Time=",stime);
    }
  }
  Alert("script is over,there are ",PeakPointCount," peak points and ",TroughPointCount," trough points");
  return(0);
}
 
tzm:
Dear all,
  The code attached is  used to detect the number of peaks and troughs in the current chart(the chart I used the EURUSD of period 1 hour) . But the scripts always alerts "0  peaks and 0 troughs" at the end of the script while I can clearly see the peaks and trough on the chart detected by the zigzag indicator. Could someone figure out what is the problem with hte code or how should tackle this issue?
  

How many buffers does the "zigzag" Indicator have ?  and what buffer number is  MODE_HIGH ?

PeakPointValue= iCustom(sym,tf,"zigzag",12,5,3  MODE_HIGH,  i);

 iCustom()     mode  -  Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions.

 
tzm:
Dear all,
  The code attached is  used to detect the number of peaks and troughs in the current chart(the chart I used the EURUSD of period 1 hour) . But the scripts always alerts "0  peaks and 0 troughs" at the end of the script while I can clearly see the peaks and trough on the chart detected by the zigzag indicator. Could someone figure out what is the problem with hte code or how should tackle this issue?
  

Dear RaptorUK,
  Many thanks for your prompt and effective reply. After going over the source code of the zigzag.mp4 in the release, I changed MODE_HIGH to be 1, and MODE_LOW to be 0. The output is what I am anticipating. In case it might be helpful to someone, I copied the right code here:
PeakPointValue= iCustom(sym,tf,"zigzag",12,5,3,1,i); //use 1 directly instead of MODE_HIGH. to get the peak point value of the zigzag indicator.
TroughPointValue= iCustom(sym,tf,"zigzag",12,5,3,0,i);//use 0 directly instead of MODE_LOW to get the trough point value of the zigzag indicator....

 

Hi Tao,

Did you manage to get this working?

Im trying to do the same.

Thanks.

 
  1. Simon Gniadkowski: How many buffers does the "zigzag" Indicator have ?  and what buffer number is  MODE_HIGH ?

    ZZ only has one buffer segment. That means between highs and lows the values are zero (IIRC otherwise EMPTY_VALUE).


  2. Ash Hashimy: Did you manage to get this working? Im trying to do the same.

    Do you really expect that people are still watching this thread after seven (7) years?
    Don't resurrect old threads without a very good reason. A lot has changed since Build 600 and Higher. 2014.02.03

Reason: