
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Prival:
Rarely, but there are situations when quotes for one instrument freeze for a long time (I saw such a situation in the yen). And if the Expert Advisor hangs on this pair, you are in trouble if you have not translated all the code into OnTime().
Lizar:
Such an event can be received using TimeCuurent(), but what to do with it further, how to synchronise it is a question.
What does TimeCuurent() have to do with this?
The help says:
In the OnTick() handler, this function will return the time of the incoming processed tick. In other cases (for example, call in OnInit(), OnDeinit(), OnTimer() handlers and so on) this is the time of arrival of the last quote for any symbol available in the "Market Watch" window, the same time that is shown in the title of this window.
The Synopsis reads:
In the OnTick() handler, this function will return the arrival time of the tick being processed. In other cases (for example, call in handlers OnInit(), OnDeinit(), OnTimer() and so on) this is the time of arrival of the last quote for any symbol available in the "Market Watch" window, the same time that is shown in the header of this window.
Yes, it is clear. only if we put it in OnTime we can update the time no more than once a minute, and if we put it in the current OnTick() we risk missing ticks on some of the pairs (in mults).
And what to do in the processing block is clear (for mults) - We get a new value, compare it with the existing one and draw conclusions whether there was a new tick or not.
But tell me, why do it in the Expert Advisor?
The Synopsis reads:
error. here is what the help says https://www.mql5.com/en/docs/basis/function/events
TheNewTick event is generated only for Expert Advisors when a new tick is received on the symbol, to whose chart the Expert Advisor is attached.
Once again. We are talking about an Expert Advisor that hangs on some symbol. It is triggered by the event
void OnTick() {}
If you are inside this function, and there are no ticks on this pair for more than an hour, you can't do anything within an hour. So far, the only way out is to do it in a timer, it starts regardless of the arrival of ticks on the instrument.
But if we put it in OnTime we can update the time no more than once a minute, and if we put it in the current OnTick() we risk missing ticks on some of the pairs (in mults).
error. Here's what the help says https://www.mql5.com/en/docs/basis/function/events.
Once again. We are talking about an Expert Advisor that hangs on some symbol. It is launched by the event
void OnTick() {}
If you are inside this function, and there are no ticks on this pair for more than an hour, you can't do anything within an hour. So far, the only way out is to do it in the timer, it is started regardless of the arrival of ticks on the instrument.
Yes, if we act within the framework of this https://www.mql5.com/en/docs/basis/function/events, I agree that the best option, as we see now, is OnTime. But it will only save us from the dependence on the arrival of ticks. And it will not save us from single-threadedness: while we are processing a signal for one instrument, we risk missing or delaying the processing of other instruments. This is especially true when "time of processing trade orders is from 2 to 7 seconds" + requotes.
I remembered about TimeCuurent() because Interesting started talking about real-time ticks for all pairs in the market review.
Very interesting article. Thank you for sharing all of this.
However, some remarks:
Talking about this function, you say :
If you call this prototype function from one place, then we have what we need. But if we want to use this function, for example, again in another place in the same calculation loop, it will always return false, which means that there is no bar. And this will not always be true. Static variable in this case imposes an artificial limit on the number of prototype function calls.
You have replaced a static local variable with a global variable, which is the same and you didn't resolve your problem.
Nevertheless, your article has the merit to push thinking and offer interesting ideas.
Good article, thanks for sharing! All that was very useful!
Anyway, I have taken your isNewBar function and it throws the following message when compiling: "possible loss of data due to type conversion".
So I have changed the var types from datetime to long this way:
Now it compiles without any notice and seems to work ok. Thank you!