Array out of range in Need of help - page 3

 

OK

over this period

 
Dark Kchlyzov:

don't get it ?

for a week or a month, the nearest minimum of what day?
 
I get it, over the whole period
 
Low_D1_Level   = iLow (_Symbol,PERIOD_D1,1);   // Возвращает значение минимальной цены бара  D1

The nearest minimum in the history is less than Low_1_Level , which will be .

Run the code to see how it works.

 
Dark Kchlyzov:

I have no errors for the whole period

I'm attaching the log

Files:
20201209.log  3729 kb
 
MakarFX:

I have no errors for the whole period

I'm attaching the log.

There seems to be no error but it is in the log

You have in your log 19:31:53.126 2016.12.15 00:00:00 Array EURUSD,H1: i = 456 Bar_data_D1 [i][2] = 1.04789

as I have a price Min_D:104789 more than low_D1 1.03660 , by convention it cannot be so.

if i replace the for loop, there will be an error. and it will be correct.

actually expression2 is just masking an error

i<ArrayRange(Bar_data_D1,0)
 for(int i = 1; ;i++)
    {
     Print(" i = ",i," Bar_data_D1 [i][2] = ",Bar_data_D1 [i][2]);
     if( Bar_data_D1 [i][2] < Low_D1_Level)
       {
        Min_D_Level = Bar_data_D1 [i][2];break;
       }
    } 


 
Dark Kchlyzov:


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

 
Dark Kchlyzov:

If you don't mind giving me an example, how to write it correctly?

I have some experience in trading, but I'm only starting to learn MQL4.

If you use MqlRates, then declare an array:

MqlRates Bar_data_D1[];

That is, you get a one-dimensional array instead of a two-dimensional one. MqlRates is a standard structure (described in MQL4 Reference under "Basics of the Language" - "Data Types" - "Structures, Classes, Interfaces"). It has all the fields that you need in this case. You can address them like this:

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

i is the index of the array.

In the same way you can create your own structure to record the parameters of candlesticks. It will be smaller than Mqlrates by two fields (spread and real_volume), which you don't need. The structure will look like this:

struct BarData
{ 
   datetime time;         // время начала периода 
   double   open;         // цена открытия 
   double   high;         // наивысшая цена за период 
   double   low;          // наименьшая цена за период 
   double   close;        // цена закрытия 
   long     tick_volume;  // тиковый объем 
};

Declaring an array of such structures looks like this:

BarData Bar_data_D1[];

Accessing members of the structure is similar to accessing members of MqlRates structure.

Документация по MQL5: Константы, перечисления и структуры / Структуры данных / Структура исторических данных
Документация по MQL5: Константы, перечисления и структуры / Структуры данных / Структура исторических данных
  • www.mql5.com
Структура исторических данных - Структуры данных - Константы, перечисления и структуры - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Ihor Herasko:

Exactly!

 
Ihor Herasko:

If via MqlRates, you declare the array like this:

That is, you get a one-dimensional array instead of a two-dimensional one. MqlRates is a standard structure (described in MQL4 Reference under "Language Fundamentals" - "Data Types" - "Structures, Classes, Interfaces"). It has all the fields that you need in this case. You can address them like this:

i is the index of the array.

In the same way you can create your own structure to record the parameters of candlesticks. It will be smaller than Mqlrates by two fields (spread and real_volume), which you don't need. The structure will look like this:

Declaring an array of such structures looks like this:

Access to members of the structure is similar to access to members of MqlRates structure.

Ok, I will try it tomorrow !

Thank you for your help. I will let you know when I figure it out.

Reason: