How to get time or shift of zigzag top (or bottom)

 

Hi i use this code in my EA to use Zigzag indicator

 int q, l;

   double r0, r1, r2, r3, r4, r5;
   l=0;
      while(q<5)
      {
      if(r0>0) {r5=r4; r4=r3; r3=r2; r2=r1; r1=r0; }
      r0=iCustom(Symbol(),0,"zigzag",depth,5,3,0,l);
      if(r0>0) {q+=1; }
      l++;
      }


The latest value of zigzag indicator is r4, and second r3, third r2 and so on....

But how do i, for example get the the time or shift of r2 ?

 

you use the same bar shift values but with:

Time[]
Time[bar]
 
Marco vd Heijden:

you use the same bar shift values but with:

But i don't have the shift values.? Or can i use r2 as shift value like:

Time[r2]
 

Aha ok i got it now its the int "l"

Thanks Marco! =)

 

Hi olzonpon,

Could you guide me the code, pleas!

 
  1.       r0=iCustom(Symbol(),0,"zigzag",depth,5,3,0,l);
    Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?

              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. Don't hard code values.
    int q, l;
    
       double r0, r1, r2, r3, r4, r5;
       l=0;
          while(q<5)
          {
          if(r0>0) {r5=r4; r4=r3; r3=r2; r2=r1; r1=r0; }
          r0=iCustom(Symbol(),0,"zigzag",depth,5,3,0,l);
          if(r0>0) {q+=1; }
          l++;
          }
    Write generalized functions, so your code is self documenting.
    void getZZ(double a[], int n, int aDepth=12, int aDeviation=5, int aBackStep=3){ 
       ArrayResize(a, n); int iA=0;
       #define ZIGZAG_EMPTY_VALUE 0
       #define ZIGZAG_BUFFER 0
       for(int iBar=0, iA < n; ++iBar){
          double value = iCustom(_Symbol, _Period, "zigzag",
                                 aDepth, aDeviation, aBackStep,
                                 ZIGZAG_BUFFER, iBar);
          if( value != ZIGZAG_EMPTY_VALUE){ a[iA] = value; ++iA; }
       }
    }
    /////////////////////
    double r[]; getZZ(r, 4, depth);

Reason: