Issues with finding a candle pattern between H6 and M20 timeframes every 6 hours using MQL5

 

Basically I have been able to write the code for the candle pattern. The candle pattern is satisfied when the upper wick of 3 consecutive timeframes has the same High and Close for a bullish candle.

The details of the pattern are explained in the attached images.

I am trying to get all the candlesticks that satisfy the condition for the three consecutive timeframes within H6 and M20 and draw a rectangles from the high to the close. The old rectangle regions should persist for 24 hours and the code is updated every 6 hours.

My current issue is several of the zones of various timeframes don’t show on the chart or appear in the log. In several cases the marked rectangle region isn’t correct, which I really don’t understand since from my check the conditions seem to be right.

Here is my code below:

input int      Input1 = 9;
//---
MqlRates m_rates_big[], m_rates_small[], m_rates_medium[];
datetime m_prev_bars                = 0;        // "0" -> D'1970.01.01 00:00';
ENUM_TIMEFRAMES period_list[] = {PERIOD_M20, PERIOD_M30, PERIOD_H1, PERIOD_H2, PERIOD_H3, PERIOD_H4, PERIOD_H6};
color color_list[] = {clrAqua, clrRed, clrYellow, clrBlue, clrCoral};

bool rectObjectFill = true;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

string prefix1 = "Pattern1";
string prefix2 = "Pattern2";
int numberOfDaysForHistory = 90;
int numberOfHours = 24;


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   ArraySetAsSeries(m_rates_big, true);
   ArraySetAsSeries(m_rates_small, true);
   ArraySetAsSeries(m_rates_medium, true);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   //ObjectsDeleteAll(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- we work only at the time of the birth of new bar on H1
   datetime time_0 = iTime(Symbol(), PERIOD_H6, 0);
   if(time_0 == m_prev_bars)
      return;
// Print("Here2");
   m_prev_bars = time_0;
//--- PERIOD_H1
   ObjectsDeleteAll(0);
   for(int period_ind = 2 ; period_ind < ArraySize(period_list); period_ind++)
     {
      ArrayFree(m_rates_big);
      ArrayFree(m_rates_small);
      ArrayFree(m_rates_medium);
      int number_of_candles_to_check = numberOfHours*60/PeriodEnumToMinutes(period_list[period_ind]);//24*numberOfDaysForHistory;;
      for(int i = 0; i < number_of_candles_to_check; i++)
        {
         int start_pos = i; // start position
         if(!CopyRates(Symbol(), period_list[period_ind], start_pos, 2, m_rates_big))
            return;
         //--- PERIOD_M30
         if(!CopyRates(Symbol(), period_list[period_ind - 1], start_pos * 2, 4, m_rates_small))
            return;
            
         if(!CopyRates(Symbol(), period_list[period_ind - 2], start_pos * 3, 6, m_rates_medium))
            return;
         //--- main loop
         
         if(
            (m_rates_big[1].high > m_rates_big[1].close) &&
            (m_rates_big[1].open < m_rates_big[1].close) &&
            (m_rates_medium[1].open < m_rates_medium[1].close) &&
            (m_rates_small[1].open < m_rates_small[1].close)
            )
           {
         if(
            (m_rates_small[1].close==m_rates_big[1].close) &&
            (m_rates_small[1].high==m_rates_big[1].high) &&
            (m_rates_medium[1].close==m_rates_big[1].close) &&
            (m_rates_medium[1].high==m_rates_big[1].high)
           )
           {
               //--- Draw rectangle here
               drawRectangle(i, m_rates_big[1].high, m_rates_big[1].low, 0, color_list[period_ind - 1], period_list[period_ind], rectObjectFill);
               Print(m_rates_small[1].time, EnumToString(period_list[period_ind]), " close is " + DoubleToString(m_rates_small[1].close));
               Print(m_rates_big[1].time,  EnumToString(period_list[period_ind - 1]), " close is " + DoubleToString(m_rates_big[1].close));
              }
           }
           }
         
        }
     }
  

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool drawRectangle(int candleInt, const double top, const double bottom, ENUM_TIMEFRAMES cDuration, color rectColor, ENUM_TIMEFRAMES period, bool shouldFillRect)
  {
   bool checkBarCount = true;
   int useCurrDuration = PeriodSeconds(cDuration) / PeriodSeconds();
   const datetime starts = iTime(_Symbol, period, candleInt);
   const datetime ends = starts - useCurrDuration * PeriodSeconds();
   const string name = prefix1 + "_" + "_" + TimeToString(starts) + TimeToString(ends);
   if(!ObjectCreate(0, name, OBJ_RECTANGLE, 0, starts, top, ends, bottom))
     {
      return false;
     }
   ObjectSetInteger(0, name, OBJPROP_COLOR, rectColor);
   ObjectSetInteger(0, name, OBJPROP_STYLE, STYLE_DASHDOT);
   ObjectSetInteger(0, name, OBJPROP_WIDTH, 1);
   ObjectSetInteger(0, name, OBJPROP_FILL, shouldFillRect);
   return true;
  }
//+------------------------------------------------------------------+


int PeriodEnumToMinutes(ENUM_TIMEFRAMES period)
{
  
   return PeriodSeconds(period)/60;
}


Please help me to fix this.

 
I still haven't been able to fix this. I really need help.