Array out of range

 
This is my completed indicator code : 

//+------------------------------------------------------------------+
//|                                                  Smart Arrow.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 4

#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 Lime
#property indicator_color4 Red

#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1

color ExtColor1 = Lime;//Color for Smart Buy Arrow
color ExtColor2 = Red;//Color for Smart Sell Arrow
color ExtColor3 = Green;//Color for Normal Buy Arrow
color ExtColor4 = Magenta;//Color for Normal Sell Arrow

double Smart_Arrow_Buy[];
double Smart_Arrow_Sell[];
double Normal_Arrow_Buy[];
double Normal_Arrow_Sell[];



input ENUM_MA_METHOD MA_Method = MODE_EMA;//MA Method
input int Number_Of_Candle_Check = 74;//Number Of Candle Check
input int Distance_Check_In_Pips = 3;//Distance Check In Pips




//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Smart_Arrow_Buy);
   SetIndexBuffer(1,Smart_Arrow_Sell);
   SetIndexBuffer(2,Normal_Arrow_Buy);
   SetIndexBuffer(3,Normal_Arrow_Sell);
   
   SetIndexLabel(0,"0: Smart Buy Arrow");
   SetIndexLabel(1,"1: Smart Sell Arrow");
   SetIndexLabel(2,"2: Normal Buy Arrow");
   SetIndexLabel(3,"3: Normal Sell Arrow");
   
   SetIndexStyle(0,DRAW_ARROW,221);
   SetIndexStyle(1,DRAW_ARROW,222);
   SetIndexStyle(2,DRAW_ARROW,225);
   SetIndexStyle(3,DRAW_ARROW,226);

   SetIndexArrow(0,221);
   SetIndexArrow(1,222);
   SetIndexArrow(2,225);
   SetIndexArrow(3,226);
   
   Draw_Arrow(NULL);
//---
   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[])
  {
//---
  Draw_Arrow(NULL);
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

void deinit()
{
ObjectsDeleteAll(0,-1,-1);
}

//+------------------------------------------------------------------+
//|Get EMA Value                                                     |
//+------------------------------------------------------------------+
double Get_EMA_Value(int Shift, string symbol, int period)
{
 return(iMA(symbol,0,period,0,MA_Method,PRICE_CLOSE,Shift));
}

//+------------------------------------------------------------------+
//|Create Objects                                                    |
//+------------------------------------------------------------------+
void Object_Create_Arrow(string Name, int Arrow_Code, datetime Time_, double Price,color Arrow_Color)
  {
   ObjectCreate(0,Name,OBJ_ARROW,0,0,0,0,0);          
   ObjectSetInteger(0,Name,OBJPROP_ARROWCODE,Arrow_Code);
   ObjectSetInteger(0,Name,OBJPROP_TIME,Time_);        
   ObjectSetDouble(0,Name,OBJPROP_PRICE,Price);
   ObjectSetInteger(0,Name,OBJPROP_COLOR,Arrow_Color);
   ObjectSetInteger(0,Name,OBJPROP_SELECTABLE,false);
  }

//+------------------------------------------------------------------+
//|Get PTS Magic Entries Values                                      |
//+------------------------------------------------------------------+
double Get_PTS_Magic_Entries_Value(int Buffer_Number, int Shift)
{
 return(iCustom(NULL,15,"PTS_Trend_WithMagicEntries_Fixed",Buffer_Number,Shift));
}

//+------------------------------------------------------------------+
//|Draw Arrow                                                        |
//+------------------------------------------------------------------+
int Pullback_Allowed_Up_1_Down_2_None_0=0,Check_For_Line_Buy_1_Sell_2_None_0=0;

void Draw_Arrow(string symbol)
{
 for(int i=Bars-1; i>0; i--)
  {
   if(Check_For_Line_Buy_1_Sell_2_None_0==1) if(Get_PTS_Magic_Entries_Value(4,i)!=EMPTY_VALUE) {Check_For_Line_Buy_1_Sell_2_None_0=0;Pullback_Allowed_Up_1_Down_2_None_0=0;}
   if(Check_For_Line_Buy_1_Sell_2_None_0==2) if(Get_PTS_Magic_Entries_Value(3,i)!=EMPTY_VALUE) {Check_For_Line_Buy_1_Sell_2_None_0=0;Pullback_Allowed_Up_1_Down_2_None_0=0;}
   
   if(Check_For_Line_Buy_1_Sell_2_None_0==0 && Open[i]<Get_EMA_Value(i,symbol,200) && Close[i]>Get_EMA_Value(i,symbol,200) && Get_PTS_Magic_Entries_Value(4,i)!=EMPTY_VALUE) 
    {
     Pullback_Allowed_Up_1_Down_2_None_0=1;
     Check_For_Line_Buy_1_Sell_2_None_0=2;
    }
   if(Check_For_Line_Buy_1_Sell_2_None_0==0 && Open[i]>Get_EMA_Value(i,symbol,200) && Close[i]<Get_EMA_Value(i,symbol,200) && Get_PTS_Magic_Entries_Value(3,i)!=EMPTY_VALUE) 
    {
     Pullback_Allowed_Up_1_Down_2_None_0=2;
     Check_For_Line_Buy_1_Sell_2_None_0=1;
    }
    
   if(Pullback_Allowed_Up_1_Down_2_None_0==1)
    {
     if(Low[i]<Get_PTS_Magic_Entries_Value(4,i))
      {
       if(Close[i]>Get_PTS_Magic_Entries_Value(4,i))
        {
         for(int j=i; j<=Number_Of_Candle_Check+i; j++)
          {
           if(NormalizeDouble(Get_EMA_Value(j,symbol,50),Digits())>NormalizeDouble(Get_EMA_Value(j,symbol,200),Digits()) && NormalizeDouble(Get_EMA_Value(j+1,symbol,50),Digits())<NormalizeDouble(Get_EMA_Value(j+1,symbol,200),Digits()))
            {
             if(
                (Close[i]>Open[i] && Close[j]>Open[j] && Close[j-1]-Close[i]>=Distance_Check_In_Pips*Point()*10)//GG
                ||(Close[i]<Open[i] && Close[j]<Open[j] && Open[j-1]-Open[i]>=Distance_Check_In_Pips*Point()*10)//RR
                ||(Close[i]<Open[i] && Close[j]>Open[j] && Close[j-1]-Open[i]>=Distance_Check_In_Pips*Point()*10)//GR
                ||(Close[i]>Open[i] && Close[j]<Open[j] && Open[j-1]-Close[i]>=Distance_Check_In_Pips*Point()*10)//RG
               ){Smart_Arrow_Buy[i]=Low[i]-(High[i]-Low[i])-2*Point()*10;Pullback_Allowed_Up_1_Down_2_None_0=0;break;}
            }
          }
         if(Smart_Arrow_Buy[i]==EMPTY_VALUE) {Normal_Arrow_Buy[i]=Low[i]-(High[i]-Low[i]);}
         Pullback_Allowed_Up_1_Down_2_None_0=0;
        }
      }
    }

   if(Pullback_Allowed_Up_1_Down_2_None_0==2)
    {
     if(High[i]>Get_PTS_Magic_Entries_Value(3,i))
      {
       if(Close[i]<Get_PTS_Magic_Entries_Value(3,i))
        {
         for(int k=i; k<=Number_Of_Candle_Check+i; k++)
          {
           if(NormalizeDouble(Get_EMA_Value(k,symbol,50),3)<NormalizeDouble(Get_EMA_Value(k,symbol,200),3) && NormalizeDouble(Get_EMA_Value(k+1,symbol,50),3)>=NormalizeDouble(Get_EMA_Value(k+1,symbol,200),3))
            {
             if(
                (Close[k]>Open[i] && Close[k-1]>Open[k-1] && Open[i]-Open[k-1]>=Distance_Check_In_Pips*Point()*10)//GG
                ||(Close[k]<Open[i] && Close[k-1]<Open[k-1] && Close[i]-Close[k-1]>=Distance_Check_In_Pips*Point()*10)//RR
                ||(Close[k]<Open[i] && Close[k-1]>Open[k-1] && Close[i]-Open[k-1]>=Distance_Check_In_Pips*Point()*10)//GR
                ||(Close[k]>Open[i] && Close[k-1]<Open[k-1] && Open[i]-Close[k-1]>=Distance_Check_In_Pips*Point()*10)//RG
               ){Smart_Arrow_Sell[i]=High[i]+(High[i]-Low[i])+2*Point()*10;Pullback_Allowed_Up_1_Down_2_None_0=0;break;}
            }
          }
         if(Smart_Arrow_Sell[i]==EMPTY_VALUE) {Normal_Arrow_Sell[i]=High[i]+(High[i]-Low[i]);}
         Pullback_Allowed_Up_1_Down_2_None_0=0;
        }
      }
    }     
  }
}
I have also attached the mq4 file.


I am getting following error(array out of range) : 

2021.08.01 16:32:24.758 Smart Arrow EURUSD,M15: array out of range in 'Smart Arrow.mq4' (210,69)

I tried array resize in OnInit then also tried to print it and found that just after I use ArraySize, Size is increased but just after few more lines on code I again printed size and found, it's Zero.

A little Bit help will be really really appreciated.

Files:
 
  1.  for(int i=Bars-1; i>0; i--)
      {
       ⋮
            {
             for(int j=i; j<=Number_Of_Candle_Check+i; j++)
              {
               ⋮
                 if(
                    (Close[i]>Open[i] && Close[j]>Open[j]

    When i equals Bars-1, you try to read [Bars-1 … Bars-1+Number_Of_Candle_check-1]. Bars and higher does not exist.

  2. Do your lookbacks correctly #9#14 & #19

    .
Reason: