Midnight candle

 

Hello I request help in coding the function I will explain below, I have already written some part of the code but I am unable to code a function that identifies the open and close of one hour midnight candle. The logic is that EA identifies one hour midnight candle close and open then drop down to 5 minutes timeframe to open orders based on my breakout conditions. Below is a code  I have written but stuck, your help will be appreciated: 

string GetEntrySignal()
  {
      string signal = "";
      
     //Find close and open of candle
     double close= iClose(_Symbol,PERIOD_H1,0);
     double open = iOpen(_Symbol,PERIOD_H1,0);
     
     
     
     return signal;
  }
 
  1. double close= iClose(_Symbol,PERIOD_H1,0);

    On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)

  2. Not tested, not compiled, just typed.
    datetime now    = TimeCurrent(), 
             today  = date(now), 
             endH1  = today + PeriodSeconds(PERIOD_H1) - 1;
    if(endH1 > now) … // No hour candle yet today.
    int      iBod   = iBarShift(_Symbol, _Period, today), 
             iEndH1 = iBarShift(_Symbol, _Period, endH1);
    double   open   = iOpen(_Symbol, Period, iBod),
             close  = iClose(_Symbol, Period, iEndH1);
    Not tested, not compiled, just typed.
              Find bar of the same time one day ago - MQL4 programming forum #1 & #6 (2017)

    See also Dealing with Time (Part 1): The Basics - MQL5 Articles (2021.10.01)
    Dealing with Time (Part 2): The Functions - MQL5 Articles (2021.10.08)
    MQL5 Programming Basics: Time - MQL5 Articles (2013.04.26)

 
William Roeder #:
  1. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)

  2. Not tested, not compiled, just typed. Not tested, not compiled, just typed.
              Find bar of the same time one day ago - MQL4 programming forum #1 & #6 (2017)

    See also Dealing with Time (Part 1): The Basics - MQL5 Articles (2021.10.01)
    Dealing with Time (Part 2): The Functions - MQL5 Articles (2021.10.08)
    MQL5 Programming Basics: Time - MQL5 Articles (2013.04.26)

Thank you I appreciate I will test it