Find candle H/L based on candle time..

 

Greetings All,

 Looking for a code to find a candle high and low based on the candle formation time. Eg.  9:00

 

Any help greatly appreciated...

 

GT..  mpfx 

 
MqlDateTime dt;
string name1,name2;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   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[])
  {
//---
   int begin=rates_total-prev_calculated;
   if(prev_calculated<1)
      begin--;
   for(int i=begin;i>=0;i--)
     {
//---Alternative 1
      TimeToStruct(time[i],dt);
      if(dt.hour==9 && dt.min==0)
        {
         name1="high"+(string)time[i];
         name2="low"+(string)time[i];
         ObjectCreate(0,name1,OBJ_ARROW,0,time[i],high[i]);
         ObjectSetInteger(0,name1,OBJPROP_ARROWCODE,217);
         ObjectSetInteger(0,name1,OBJPROP_COLOR,clrBlue);
         ObjectCreate(0,name2,OBJ_ARROW,0,time[i],low[i]);
         ObjectSetInteger(0,name2,OBJPROP_ARROWCODE,217);
         ObjectSetInteger(0,name2,OBJPROP_COLOR,clrRed);
        }
//---Alternative 2
      if(TimeHour(time[i])==9 && TimeMinute(time[i])==0)
        {
         name1="high"+(string)time[i];
         name2="low"+(string)time[i];
         ObjectCreate(0,name1,OBJ_ARROW,0,time[i],high[i]);
         ObjectSetInteger(0,name1,OBJPROP_ARROWCODE,217);
         ObjectSetInteger(0,name1,OBJPROP_COLOR,clrBlue);
         ObjectCreate(0,name2,OBJ_ARROW,0,time[i],low[i]);
         ObjectSetInteger(0,name2,OBJPROP_ARROWCODE,217);
         ObjectSetInteger(0,name2,OBJPROP_COLOR,clrRed);
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
Ernst Van Der Merwe:
Thank you Ernst..  Very much appreciated..   GT...
Reason: