Questions from Beginners MQL5 MT5 MetaTrader 5 - page 601

 

Hi all!

Give advice, solution or poke around where to read.

Solving a problem: error handling when iCustom() is called...

// MQL4
void OnTick()
{
....
   ResetLastError();
   double val=iCustom(NULL,0,INDUK_NAME,..., i);
   if ((nErr=GetLastError())>0)
   {
      Print("Error in ",__FUNCTION__," code=",nErr);
      ExpertRemove();
      return;
   }
...
}

This code construction doesn't work if "iCustom" crashed with "array out of range" message when debugging EA in tester.

 
An array overrun is a critical error, after whichprogram execution stops and no further code is executed. That is why your error handler does not work. And you do not need error code in this case - it is written in black and white in the log what caused the crash. And even specified line and position where it happened.
 
Sergei Vladimirov:
Array overrun is a critical error, after whichthe program stops and no further code is executed. That's why your error handler does not work. And you do not need the error code in this case, it is written black and white in the journal what caused the crash. And even specified line and position where it happened.

1. I know that the error is in the logbook and that it is critical

2. I don't understand why the tester doesn't stop the EA and has to force a stop?

Are there any language constructs for handling exceptions to organize the Expert Advisor and its interaction with the user in a convenient way in case of critical errors?

 
fromme2you:

1. I know that the error is in the logbook and that it is critical

2. I don't understand why the tester doesn't stop the EA and has to force a stop?

3. Are there any language constructs for handling exceptions, to organize the Expert Advisor and its interaction with the user in a convenient way in case of critical errors?

The tester stops if a critical error (eg, division by 0, or an array overrun) has occurred in the code of the Expert Advisor.

Avoid stopping the code in the tester or in the real code, I think, is possible only if we introduce the appropriate checks into the code. Which is not always feasible. This is especially true if you are using someone else's code or paste someone else's code as a subroutine in your product.

Another tricky way is to read the log files programmatically.

 
Yuri Evseenkov:

The tester stops if a critical error (e.g. division by 0 or exceeding an array) occurs in the code of the advisor itself....

Another tricky way is to read logs programmatically.

I see, thanks for the reply.

Another question: how can I get MT4 developer and MQL code runtime to put some thought and effort into developing a language for handling exceptions such as in my example, or a similar one?

 
fromme2you:

I see, thanks for the answer.

Another question: how can I get MT4 and MQL code execution environment developers to put their minds and hands into developing a language for exception handling, such as in my example or similar in meaning?

Contact servesdesk, create a thread/survey on the forum.

It wasn't so long ago that MT4 was buried. Now the trend, if not reversed, at least the platform and the language have been significantly upgraded recently.

 
Yuri Evseenkov:

Contact servesdesk, create a forum topic/survey.

It wasn't that long ago that MT4 was being buried. Now the trend, if not reversed, at least the platform and language have been significantly upgraded recently.

it was buried for the first time in 2009

 

Hello. If you're familiar with the subject, please advise how to solve this problem. I want to find the open prices of bars at a certain time, for example at 01:00, by analyzing for example 50 latest bars. I'm not sure how to go about this task in mql5.


Whether by calculating the current date + adding the required time to it and then adding twenty-four hours, this method worked on mql4.

As far as I understood, there are special structures with time output, but I can't use them for some reason.

Thanks in advance for the feedback.

I would be very grateful if somebody could throw me a small piece of code to understand the thinking process.
 
Alex:

Hello. If you're familiar with the subject, please advise how to solve this problem. I want to find the open prices of bars at a certain time, for example at 01:00, by analyzing for example 50 latest bars. I'm not sure how to go about this task in mql5.


Whether by calculating the current date + adding the required time to it and then adding twenty-four hours, this method worked on mql4.

As far as I understood, there are special structures with time output, but I can't use them for some reason.

Thanks in advance for the answer.

I would be very grateful if somebody could throw me a bit of code to understand the thinking process.
In an indicator or in an EA/script?
 
Hi. Question: if i use ordersendasync in mt5 for a pending order, how will it work? For example, will it send a buy stop without waiting for a reply, but when the order triggers, will it wait for the server to reply to the buy order?
Reason: