zigzag peak date

 

Hi, I am having trouble getting the zigzag peak date or the date of the candle where the zigzag created a high or low points

I have gone through all threads i found talking about the zigzag.

This is what I have

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---One Time convert points to a price gap
   static double levelGap = InpGapPoints;
   DrawLevels();
   if(rates_total == prev_calculated)
      return(rates_total);

//Get the most recent <lookback> peaks
   double zz = 0;
   datetime tt;
   double zzPeaks[];
   datetime swing_date[];
   int zzCount = 0;
   static datetime TIME[];
   ArrayResize(zzPeaks, InpLookBack);
   ArrayInitialize(zzPeaks,0.0);

   ArrayResize(swing_date, InpLookBack);
   ArrayInitialize(swing_date,0.0);

   int count = CopyBuffer(Handle, 0, 0,rates_total, Buffer);
   CopyTime(Symbol(),PERIOD_CURRENT,0,rates_total,TIME);

   if(count < 0)
     {
      int err = GetLastError();
      return(0);
     }

   for(int i = 1; i < rates_total && zzCount < InpLookBack; i++)

     {
      zz = Buffer[i];
      if(zz != 0&& zz != EMPTY_VALUE)
        {

         zzPeaks[zzCount] = zz;
         swing_date[zzCount] = tt;
         zzCount++;

        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 

Sphelele Sphesihle Lubanyana: I am having trouble getting the zigzag peak date or the date of the candle where the zigzag created a high or low points


This is what I have

You never read in or use any time.
   datetime tt;
   ⋮
         swing_date[zzCount] = tt;
No need for the CopyTime
Simplify
         swing_date[zzCount] = iTime(NULL,0, i);
 

I finally cracked it.. I hope this helps someone else...

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[])
  {
//---One Time convert points to a price gap
   static double levelGap = InpGapPoints;
   DrawLevels();
   if(rates_total == prev_calculated)
      return(rates_total);

//Get the most recent <lookback> peaks
   double zz = 0;
   datetime tt;
   double zzPeaks[];
   int zzCount = 0;
   ArrayResize(zzPeaks, InpLookBack);
   ArrayInitialize(zzPeaks,0.0);

   int count = CopyBuffer(Handle, 0, 0,rates_total, Buffer);

   if(count < 0)
     {
      int err = GetLastError();
      return(0);
     }

   for(int i = 1; i < rates_total && zzCount < InpLookBack; i++)

     {
      zz = Buffer[i];
      if(zz != 0&& zz != EMPTY_VALUE)
        {

         zzPeaks[zzCount] = zz;

         zzCount++;
         for(int i = 1; i < rates_total ; i++)
           {
            if(zzPeaks[zzCount-1] == low[i])
               Print(time[i]);
           }
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
Sphelele Sphesihle Lubanyana #: I finally cracked it.. I hope this helps someone else...

“Cracked it?” Your code still doesn't give you any time. That was your original problem:

Sphelele Sphesihle Lubanyana: I am having trouble getting the zigzag peak date or the date of the candle where