Array out of range in Need of help - page 4

 
Dark Kchlyzov:

There doesn't seem to be an error, but it's in the log.


You were right originally, due to lack of near minimum

ran from 2002 and in 2016 everything is fine.

 
MakarFX:

You were right initially, for lack of a near minimum

ran from 2002 and in 2016 all is well .

AUDUSD 2020 same thing. Remove from the cycle for 2 expression there is an error , if we leave it there is no error , just on that day we do not redraw the line

Do you have the same check?

strange that the loop almost always breaks at 1001 bars (maybe the array limit ?)


2020.12.10 09:56:40.177 2020.03.02 00:01:00 Test_Level AUDUSD,H1: array out of range in 'Test_Level.mq4' (51,59)

2020.12.10 09:56:40.177 2020.03.02 00:01:00 Test_Level AUDUSD,H1: i = 1001 Bar_data_D1 [i][2] = 0.77324

2020.12.10 09:56:40.177 2020.03.02 00:01:00 Test_Level AUDUSD,H1: i = 1000 Bar_data_D1 [i][2] = 0.76934

2020.12.10 09:56:40.177 2020.03.02 00:01:00 Test_Level AUDUSD,H1: i = 999 Bar_data_D1 [i][2] = 0.76907

2020.12.10 09:56:40.177 2020.03.02 00:01:00 Test_Level AUDUSD,H1: i = 998 Bar_data_D1 [i][2] = 0.76963

2020.12.10 09:56:40.177 2020.03.02 00:01:00 Test_Level AUDUSD,H1: i = 997 Bar_data_D1 [i][2] = 0.7548



//+------------------------------------------------------------------+
//|                                                   Test_Level.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
double   Bar_data_D1 [][6]; // Копирует в массив данные баров указанного графика и возвращает количество скопированных баров D1
double   Low_D1_Level;      // Возвращает значение минимальной цены бара  D1
double   Min_D_Level ;      // ближайшей минимальный  D уровень
datetime  Time_Day;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   Level();
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  On_Timer();
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                        Функция Level 
//+------------------------------------------------------------------+
void Level()
{
 ArrayCopyRates(Bar_data_D1,_Symbol,PERIOD_D1); // Копирует в массив данные баров указанного графика и возвращает количество скопированных баров

 Low_D1_Level   = iLow (_Symbol,PERIOD_D1,1);   // Возвращает значение минимальной цены бара  D1
    
//--- Min_D_Leve  
 //for(int i = 1; i<ArrayRange(Bar_data_D1,0) ;i++)
 for(int i = 1; ;i++)
    {
     Print(" i = ",i," Bar_data_D1 [i][2] = ",Bar_data_D1 [i][2]);
     if(Bar_data_D1 [i][2]>=0)
       {
        if( Bar_data_D1 [i][2] < Low_D1_Level)
          {
           Min_D_Level = Bar_data_D1 [i][2];break;
          }
       }   
    } 

 //+-------------------------Low_D1_Level----------------------------+ 
 if(ObjectFind("Low_D1")!=Low_D1_Level) 
   {
    ObjectDelete("Low_D1");
    if(ObjectFind("Low_D1")!=0)
      {
       ObjectCreate("Low_D1",OBJ_HLINE, 0, Time[0],Low_D1_Level);
       ObjectSet("Low_D1", OBJPROP_COLOR, clrMaroon);
       ObjectSet("Low_D1", OBJPROP_WIDTH, 1);
      }
   } 
   
 if(ObjectFind("Low_D1_label")!=Low_D1_Level)
   {
    ObjectDelete("Low_D1_label"); 
    if(ObjectFind("Low_D1_label") != 0)
      {
       ObjectCreate("Low_D1_label", OBJ_TEXT, 0, Time[13], Low_D1_Level);
       ObjectSetText("Low_D1_label", "Low_D1: " + DoubleToStr(Low_D1_Level,_Digits), 8,"Verdana", Brown);
      }
   } 
   
 //+-------------------------Min_D_Level----------------------------+ 
 if(ObjectFind("Min_D")!= Min_D_Level) 
   {
    ObjectDelete("Min_D");
    if(ObjectFind("Min_D")!=0)
      {
       ObjectCreate("Min_D",OBJ_HLINE, 0, Time[0],Min_D_Level);
       ObjectSet("Min_D", OBJPROP_COLOR, clrMaroon);
       ObjectSet("Min_D", OBJPROP_WIDTH, 1);
      }
   } 
   
 if(ObjectFind("Min_D_label")!=Min_D_Level)
   {
    ObjectDelete("Min_D_label"); 
    if(ObjectFind("Min_D_label") != 0)
      {
       ObjectCreate("Min_D_label", OBJ_TEXT, 0, Time[30], Min_D_Level);
       ObjectSetText("Min_D_label", "Min_D: " + DoubleToStr(Min_D_Level,_Digits), 8,"Verdana", Brown);
      }
   }  
 
}
//+------------------------------------------------------------------+
//|        функция удаление всех объектов созданных советником
//+------------------------------------------------------------------+
void DestroyObject()
{
 int tot=ObjectsTotal();
 for( int i=tot; i>=0; i--)
    {
     
     if(ObjectName(i)=="Low_MN1"){ObjectDelete(0,"Low_MN1");Print("<< Объект Low_MN удалён >>");}
     if(ObjectName(i)=="Low_MN1_label"){ObjectDelete(0,"Low_MN1_label");Print("<< Объект Low_MN1_label удалён >>");}
     

     if(ObjectName(i)=="Min_D"){ObjectDelete(0,"Min_D");Print("<< Объект Min_D удалён >>");}
     if(ObjectName(i)=="Min_D_label"){ObjectDelete(0,"Min_D_label");Print("<< Объект Min_D_label удалён >>");}


   }
}
//+-------------------------------------------------------------------------+   
//                         функция Timer                    
//+-------------------------------------------------------------------------+
void On_Timer()
{

     
 if(Day()!= Time_Day)
   {
    Level();
    Time_Day = Day();
   }
}

 
Aleksei Stepanenko:

There is a question. Why do you start the loop from the first element, and not from zero?

If Low_D1_Level is the level of the previous day, then Min_D_Level should be looked for fromLow_D1_Level and it is equal to i=1 , or I am mistaken?

 
Dark Kchlyzov:


it is strange that the loop almost always breaks at 1001 bars (maybe the array limit?)


not always

2020.12.10 08:16:47.604 EURUSD,H1: 265 tick events (265 bars, 13782 bar states) processed in 0:00:53.781 (total time 0:00:55.813)
2020.12.10 08:16:47.604 2016.12.16 00:00:00  Testing pass stopped due to a critical error in the EA
2020.12.10 08:16:47.604 2016.12.16 00:00:00  Array EURUSD,H1: array out of range in 'Array.mq4' (51,59)
2020.12.10 08:16:47.604 2016.12.16 00:00:00  Array EURUSD,H1:  i = 1011 Bar_data_D1 [i][2] = 1.32667
2020.12.10 08:16:47.604 2016.12.16 00:00:00  Array EURUSD,H1:  i = 1010 Bar_data_D1 [i][2] = 1.32642
2020.12.10 08:16:47.604 2016.12.16 00:00:00  Array EURUSD,H1:  i = 1009 Bar_data_D1 [i][2] = 1.32857
2020.12.10 08:16:47.604 2016.12.16 00:00:00  Array EURUSD,H1:  i = 1008 Bar_data_D1 [i][2] = 1.335
2020.12.10 08:16:47.604 2016.12.16 00:00:00  Array EURUSD,H1:  i = 1007 Bar_data_D1 [i][2] = 1.34244
2020.12.10 08:16:47.604 2016.12.16 00:00:00  Array EURUSD,H1:  i = 1006 Bar_data_D1 [i][2] = 1.3414
2020.12.10 08:16:47.604 2016.12.16 00:00:00  Array EURUSD,H1:  i = 1005 Bar_data_D1 [i][2] = 1.34815
2020.12.10 08:16:47.604 2016.12.16 00:00:00  Array EURUSD,H1:  i = 1004 Bar_data_D1 [i][2] = 1.35409
2020.12.10 08:16:47.604 2016.12.16 00:00:00  Array EURUSD,H1:  i = 1003 Bar_data_D1 [i][2] = 1.35726
 

AUDUSD is not like that for me

2020.12.10 08:22:28.794 AUDUSD,H1: 121 tick events (121 bars, 3166 bar states) processed in 0:00:00.000 (total time 0:00:02.016)
2020.12.10 08:22:28.794 2020.03.10 00:00:00  Testing pass stopped due to a critical error in the EA
2020.12.10 08:22:28.794 2020.03.10 00:00:00  Array AUDUSD,H1: array out of range in 'Array.mq4' (51,59)
2020.12.10 08:22:28.794 2020.03.10 00:00:00  Array AUDUSD,H1:  i = 1049 Bar_data_D1 [i][2] = 0.71997
2020.12.10 08:22:28.794 2020.03.10 00:00:00  Array AUDUSD,H1:  i = 1048 Bar_data_D1 [i][2] = 0.71453
2020.12.10 08:22:28.794 2020.03.10 00:00:00  Array AUDUSD,H1:  i = 1047 Bar_data_D1 [i][2] = 0.71557
2020.12.10 08:22:28.794 2020.03.10 00:00:00  Array AUDUSD,H1:  i = 1046 Bar_data_D1 [i][2] = 0.7117599999999999
2020.12.10 08:22:28.794 2020.03.10 00:00:00  Array AUDUSD,H1:  i = 1045 Bar_data_D1 [i][2] = 0.7108
2020.12.10 08:22:28.794 2020.03.10 00:00:00  Array AUDUSD,H1:  i = 1044 Bar_data_D1 [i][2] = 0.71086
2020.12.10 08:22:28.794 2020.03.10 00:00:00  Array AUDUSD,H1:  i = 1043 Bar_data_D1 [i][2] = 0.7160300000000001
2020.12.10 08:22:28.794 2020.03.10 00:00:00  Array AUDUSD,H1:  i = 1042 Bar_data_D1 [i][2] = 0.7281
2020.12.10 08:22:28.794 2020.03.10 00:00:00  Array AUDUSD,H1:  i = 1041 Bar_data_D1 [i][2] = 0.73392
 
Dark Kchlyzov:

I'm not sure, but I think you need to insert something like

if(Bar_data_D1 [i][2]==EMPTY_VALUE)Bar_data_D1 [i][2]=Low_D1_Level;
 
MakarFX:

I'm not sure, but I think you need to put something like


Like for an indicator ?

EMPTY_VALUE

Empty value in indicator buffer

 
Dark Kchlyzov:


Kind of like for an indicator ?

EMPTY_VALUE

Empty value in indicator buffer

Now it's time to study the structures

how and where to correctly declare MqlRates

Bar_data_D1[i].high; Максимум свечи
Bar_data_D1[i].low; Минимум свечи

you can if you have some time and it's not too much trouble ( example in the code )

The C++ code is full of information, but MQL4 does not give a clear explanation of what's what.

 

Dark Kchlyzov:

I can if I have some time and it's not too much trouble (example in the code).


Sorry, I am not a programmer, I am just curious.

Instead of EMPTY_VALUE you can useNULL


 
Dark Kchlyzov:

Now it is time to study the structures

how and where to declare MqlRates correctly

If you have some time and it's not too much trouble ( example in the code )

I have a lot of information in C++, but MQL4 as for me, it doesn't explain properly how and what to do.

I don't even know what else to add. In principle, I have given the main examples. This is the code. That's why I recommend you to tell me, what's unclear.

Reason: