//+------------------------------------------------------------------+
//|                                            HighLowTime-naick.mq5 |
//|                                          Copyright 2024,JBlanked |
//|                                        https://www.jblanked.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024,JBlanked"
#property link      "https://www.jblanked.com/"
#property version   "1.00"

// main issue is that you cant apply datetimes to buffers
// second issue is the buffers aren't set correctly (missing label, width, style, and type
// third issue is that it's checking if the current high/low equals the current high/low, which will always be true

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
// Buffers for high and low times
double HighTimeBuffer[];
double LowTimeBuffer[];
// Initialization function
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
// Create buffers
   SetIndexBuffer(0, HighTimeBuffer);
   SetIndexBuffer(1, LowTimeBuffer);
// Set indicator names
   IndicatorSetString(INDICATOR_SHORTNAME,"High and Low Time");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
// Ensure we have at least one bar to work with
   if(rates_total < 2)
      return (0);
// Iterate over the bars
   for(int i = 1; i < rates_total; i++)
     {
      // Set the default values
      HighTimeBuffer[i] = EMPTY_VALUE;
      LowTimeBuffer[i] = EMPTY_VALUE;
      // Check if current high is the highest for the bar
      if(high[i] == iHigh(NULL, 0, i))
        {
         // HighTimeBuffer[i] = time[i];
         HighTimeBuffer[i] = high[i];
        }

      // Check if current low is the lowest for the bar
      if(low[i] == iLow(NULL, 0, i))
        {
         // LowTimeBuffer[i] = time[i];
         LowTimeBuffer[i] = low[i];
        }

     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
