Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1173

 

MQL5 iBarShift

According to mql5 documentation, the iBarShift function returns a value of int type.

int#

The int type has a size of 4 bytes (32 bits). The minimum value is -2 147 483 648, the maximum value is 2 147 483 647.


MyiBarShift does not want to give a value greater than 99999

I draw a trend line on the chart, the following script gets the start time of the line and outputs the bar number of that time.

When the line is shifted back in the history at some point the output value stops at 99999, and if

boolexact=false// mode

change it to true, it prints -1, and GetLastError = 0

void OnStart()
  {
int total = ObjectsTotal(0, 0, -1);  // Общее кол-во объектов на: /текущий график/главное окно/все типы объектов
datetime time0 = 0; // Время соответствующее началу трендовой линии
string objname = ""; // Имя объекта (трендовой линии)
int shift = 0; // Номер бара, соответствующего времени начала трендовой линии time0

for(int i = total - 1; i >= 0; i--)
     {
     objname = (string)ObjectName(0, i, 0, OBJ_TREND);
     time0 = ObjectGetInteger(0, objname, OBJPROP_TIME, 0);
     shift = iBarShift(NULL, PERIOD_M1, time0, false);
     Comment("shift: ", shift, " Error: ", GetLastError());
     Sleep(2000);
     }
  }

What's wrong?

I tried different charts of different brokers, the time from the line is reading correctly, if I change PERIOD_M1 to M5, for example, then I need to move further in the history to reach 99999

Документация по MQL5: Основы языка / Типы данных / Целые типы / Типы char, short, int и long
Документация по MQL5: Основы языка / Типы данных / Целые типы / Типы char, short, int и long
  • www.mql5.com
Целый тип char занимает в памяти 1 байт (8 бит) и позволяет выразить в двоичной системе счисления 2^8 значений=256. Тип char может содержать как положительные, так и отрицательные значения. Диапазон изменения значений составляет от -128 до 127. uchar # Целый тип uchar также занимает в памяти 1 байт, как и тип char, но в отличие от него, uchar...
Files:
sc1.mq5  3 kb
 
Sunriser:

MQL5 iBarShift

According to mql5 documentation, the iBarShift function returns a value of int type.

int#

The int type has a size of 4 bytes (32 bits). The minimum value is -2 147 483 648, the maximum value is 2 147 483 647.


MyiBarShift does not want to give a value greater than 99999

I draw a trend line on the chart, the following script gets the start time of the line and outputs the bar number of that time.

When the line is shifted back in the history at some point the output value stops at 99999, and if

boolexact=false// mode

change it to true, it prints -1, and GetLastError = 0

What's wrong?

I tried different charts of different brokers, the time from the line is reading correctly, if I change PERIOD_M1 to M5, for example, I need to move further in the history to reach 99999.

First of all check the maximum number of bars in the terminal settings.

 
Uladzimir Izerski:

First check the maximum number of bars in the terminal settings.

Thank you!

It was 10000, changed it to unlimited and it worked.

Not an obvious thing though...

 

Help in creating handles

Here's the thing

int OnInit()
  {
//-создадим хэндл индикатора
      handle=iAO(name,period);
//-если не удалось создать хэндл
   if(handle==INVALID_HANDLE)
     {
      ...
      return(INIT_FAILED);
     }

Question: From what parameters is the number (digits) of a handle assigned?
Can it be different after restarting the terminal?
Can it be different after a chart reinitialization?
In what cases can it change?

 
Vitaly Muzichenko:

Help in creating handles

Here's the thing

Question: From what parameters is the number (digits) of a handle assigned?
Can it be different after restarting the terminal?
Can it be different after a chart reinitialization?
In what cases can it change?

If there is only one indicator, it always has a handle of 10. Each successive one is equal to the previous one+1 and it all depends on the order in which the handles were created. It can only change if one of the previous ones gets an error.

 
Alexey Viktorov:

If you have one indicator, it always has a handle of 10. Each next one is equal to the previous one+1 and it all depends on the order in which the handles were created. It can only change if one of the previous ones gets an error.

I see, it's more or less understood. Thank you!

 
Vitaly Muzichenko:

Help in creating handles

There's a thing like this

Question: From what parameters is the number (digits) of a handle assigned?
Can it be different after restarting the terminal?
Can it be different after a chart reinitialisation?
In what cases can it change?

Found answers

Сравниваем скорость самокэширующихся индикаторов
Сравниваем скорость самокэширующихся индикаторов
  • www.mql5.com
Предположим, что нам вдруг наскучил классический MQL5-доступ к индикаторам и захотелось сравнить скорость доступа в сравнении с альтернативными вариантами. Например, сравним его с доступом к индикаторам в стиле MQL4 без кэширования и с кэшированием. Идеи с доступом в MQL4-стиле были взяты из статьи LifeHack для трейдера: готовим фастфуд из...
 
Where is it possible to insert a file so that it is visible, via inheritance, to all the files in the standard library?
Документация по MQL5: Стандартная библиотека
Документация по MQL5: Стандартная библиотека
  • www.mql5.com
Стандартная библиотека MQL5 написана на языке MQL5 и предназначена для облегчения написания программ (индикаторов, скриптов, экспертов) конечным пользователям. Библиотека обеспечивает удобный доступ к большинству внутренних функций MQL5.
 

Please advise how to correctly pass a multidimensional array into a function.

If I simply specify MyFun( &Mas[][] ) in the header, the compiler generates an error on accessing an array element Mas[j][k] in the function body... But how?

There seems to be no problem with one-dimensional ones.

 
User_mt5:

Please advise how to correctly pass a multidimensional array into a function.

If I simply specify MyFun( &Mas[][] ) in the header, the compiler generates an error on accessing an array element Mas[j][k] in the function body... But how?

There seems to be no problem with one-dimensional arrays.

The second and the next array's dimensions cannot be dynamic. Consequently, it must be MyFun(int &Mas[][7]) declared as an array, for example, int Mas[][7]; so it should be received.

Reason: