Errors, bugs, questions - page 2932

 

Error in description:

Error

This field is called: time_type

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

I am trying to allow the user to select both timeframes and their number from the menu of the indicator setup window:

and I want the selected periods to go directly to PArray. But from the above example it turns out that I assign to the array the values pre-set in the program and not the values entered by a user. In addition, the compiler generates warnings:

When I try to replace the last line with:

the compiler generates an error altogether:

Also, NO_PERIOD=0 meansPERIOD_CURRENT, and I don't need that, I need something like false or EMPTY_VALUE, but they don't fit at all.

How do I fix it?

Almost fixed it.

 
The symbol settings in the tester do not hold, trading sessions are cut on Thursday and Friday, because of this there is always an error market closed, positions are not opened, optimisation is impossible, the robot does not work properly, other brokers are fine, but this one is needed, what to do? I don't know why I tried it before. I don't know, I don't know if I have already registered the trading robot, but I've never been able to open positions. Who knows what to do? Registered a new account, cleaned the terminal from temporary files, tried another terminal, no help. video problems https://radikal.ru/video/1HA3UfUNVZt
Документация по MQL5: Получение рыночной информации / SymbolInfoSessionQuote
Документация по MQL5: Получение рыночной информации / SymbolInfoSessionQuote
  • www.mql5.com
SymbolInfoSessionQuote - Получение рыночной информации - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Could you tell us what methods of fighting the "array out of range" error are available? Firstly, I cannot use Print to print an array element which has gone out of range because the error is too far ahead of it and it never reaches printing. Secondly, this error appears not systematically, but as it pleases: it has appeared once and the indicator hasn't worked (yet it is present in the indicator list in the chart), all the next times it hasn't occurred, without recompiling the indicator, nothing to say about its modification.
Документация по MQL5: Основы языка / Переменные
Документация по MQL5: Основы языка / Переменные
  • www.mql5.com
Переменные - Основы языка - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
x572intraday:
Tell me, what methods of fighting exist for catching and correcting "array out of range" error?

ArrayResize() do before writing an array element, count and enter there the number of elements that should be in the array, or use a dynamic array that itself gets fat. You're just going outside the array, for example you specify a size of 100 elements, but since the first element is #0 some people get confused, if you write the numbers in a row you'll fit 0-99. I'm not a professional programmer if anything(but I can), the first thing that came into my head, it works)))

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

Do ArrayResize() before writing an element of the array, count and enter there the number of elements that should be in the array, or use a dynamic array that grows itself.

Actually, it's dynamic anyway. From the help:"The function can only be applied to dynamic arrays. Note that dynamic arrays assigned as indicator buffers by the SetIndexBuffer() function should not be resized. For indicator buffers, all resizing operations are performed by the executing subsystem of the terminal. "But it is not an indicator buffer, so you have to think with your hands and head...

 
x572intraday:

Actually, it's already dynamic. From the help:"The function can only be applied to dynamic arrays. You should bear in mind that dynamic arrays assigned as indicator buffers by the SetIndexBuffer() function cannot be resized. For indicator buffers, all resizing operations are performed by the executing subsystem of the terminal. "But it's not an indicator buffer, so you'll have to think with your hands and head...

The problem of catching such errors is only solved by using "layers", such as a custom array class that intercepts addressing.

MQL's OOP notes: rubber arrays, safe numbers, exceptions handling and other tricks: part 1
MQL's OOP notes: rubber arrays, safe numbers, exceptions handling and other tricks: part 1
  • 2016.11.08
  • www.mql5.com
Today we're starting a patchy subject, which will combine many different things. This is why I decided to split it into parts. Out final goal is exception handling, but before we can address it, we
 

When launching the EA when algotrading is disabled and then turning on the algotrading:

According to the error code, the trade ban remains, although the TERMINAL_TRADE_ALLOWED property is true

#include <Greshnik\\ErrorDescription.mqh>
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED))
     {
      return;
     }
   MqlTradeRequest tr;
   MqlTradeResult r;
   ResetLastError();
   if(!OrderSend(tr,r))
     {
      int err=GetLastError();
      Print(err,"  ",cLng::CodeDescription(err));
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
2020.12.30 15:25:38.629 Experts automated trading is enabled
2020.12.30 15:25:39.159 Test1 (EURUSD,M1)       4752  Торговля для эксперта запрещена
2020.12.30 15:25:40.297 Test1 (EURUSD,M1)       4752  Торговля для эксперта запрещена
2020.12.30 15:25:40.397 Test1 (EURUSD,M1)       4752  Торговля для эксперта запрещена
2020.12.30 15:25:40.499 Test1 (EURUSD,M1)       4752  Торговля для эксперта запрещена
2020.12.30 15:25:40.725 Test1 (EURUSD,M1)       4752  Торговля для эксперта запрещена
2020.12.30 15:25:42.781 Test1 (EURUSD,M1)       4752  Торговля для эксперта запрещена
2020.12.30 15:25:43.129 Test1 (EURUSD,M1)       4752  Торговля для эксперта запрещена
2020.12.30 15:25:43.758 Experts automated trading is disabled

The result should be as follows:

2020.12.30 15:29:58.406 Experts automated trading is enabled
2020.12.30 15:30:02.247 Test1 (EURUSD,M1)       4756  Не удалось отправить торговый запрос
2020.12.30 15:30:02.368 Test1 (EURUSD,M1)       4756  Не удалось отправить торговый запрос
2020.12.30 15:30:02.486 Test1 (EURUSD,M1)       4756  Не удалось отправить торговый запрос
2020.12.30 15:30:04.320 Experts automated trading is disabled
 
CopyTime(_Symbol,tf,0,1,Arr);
Obviously, must always ArraySize(Arr)=1. This is in the case of successful copying. But in what cases the copying of the bar might fail? Whenthe "array out of range" error occurs, the terminal points to Arr[0].
 
x572intraday:
Obviously, it should always be ArraySize(Arr)=1. This is in the case of successful copying. But in what cases the copying of the bar might fail? When the"array out of range" error occurs, the terminal points to Arr[0].

Caught the error after all, quote from the help:

4401

Requested history not found.

Printed it to the Logbook - got it:

2020.12.31 14:45:20.474 test (EURUSD,H2)        ArraySize(Arr)=0; copied=-1; TF=PERIOD_H2
2020.12.31 14:45:20.474 test (EURUSD,H2)        Error Code = 4401

What do I do with it now, where do I go? Am I a bad hand or...? I'm only copying one bar from 0 to 1, after all. How can it (history) not be? The more so, the error doesn't always reveal itself. Or is it necessary to forcibly check and load the history beforehand?

Reason: