Questions how to ensure EA is constantly checking current price - page 2

 
Stuart Browne:

Welcome mate :)

How fast the program completes is totally dependent on what logic needs to be executed in each tick event, along with any other events that are firing (eg Timer events, chart events, web requests, file operations etc etc). And how quickly every tick arrives is totally dependant on the pair. Some volatile pairs could have multiple ticks per second, some might only have a few a minute. 

But in general, MQ code is pretty efficient as a language (as long as it's programmed well!) so can handle most situations you would want to program without many problems. Though I personally wouldn't use it for high frequency micro pip scalping!

Re the MA, yes, if you use the current close value (ie the current bid), the MA value of the current candle will keep fluctuating. That's why most MA strategies use the close value of the previous bar (Close[1])

Start() is pretty much a deprecated function with the latest builds and differs depending on the type of program using it. but is basically equivalent to OnTick and OnCalculate. Probably best if you read up the docs here and here

Finally, if you're worried about execution speed, you need to keep in mind that indicators all run in the same thread whereas EAs run in their own threads. But as I said, for 99% of what you want to get out of MT, it shouldn't be a problem.

That's really cool. Thanks a lot
 
Very welcome :D
 
Stuart Browne:
Yes, OnTick() will execute on every tick. But if OnTick() is still processing when a new tick arrives it won't process the new tick

Where is this information taken from? Its right that OnTick() is not executed recursively, but I dont believe that it drops ticks, rather its all queued just like chart events. I made measurements in the past regarding this an never ever missed one single tick. Furthermore Ive posted such measurements here where Ive been discussing this here in another thread as far as I remember right. Itll be a desaster anyway, cause it would mean that other windows processes could cause the missing of ticks too, if MT would measure the time and if these processes would be executed parallel.

Its also not about execution speed of the code which matters here, its only the speed of the brokers server which is at least 20ms per command, while the code rarely needs more than 1ms to process. And as said, I never saw that one single tick was ever missed even if the process closed 100 positions in between - live - and I am highly interested in the source of your information regarding this statement. 

 

Yes, it drops ticks if OnTick() etc is still processing (not queued) -> https://www.mql5.com/en/docs/runtime/running

 

Documentation on MQL5: MQL5 programs / Program Running
Documentation on MQL5: MQL5 programs / Program Running
  • www.mql5.com
MQL5 programs / Program Running - Reference on algorithmic/automated trading language for MetaTrader 5
 

Nope. Either I am blind or you misunderstand the information which says only "not processed", but not dropped.

void

OnTick

none

Expert Advisors

NewTick event handler. While the event of a new tick receipt is being processed, no other events of this type are received.

 
Doerk Hilger:

Nope. Either I am blind or you misunderstand the information which says only "not processed", but not dropped.

void

OnTick

none

Expert Advisors

NewTick event handler. While the event of a new tick receipt is being processed, no other events of this type are received.

Then maybe you are blind? Or maybe you misunderstand the information.....? It's OK, I asked a similar question a few days ago.

Chart events are also not queued, we also went through this discussion a few days ago on the forum.

 All events are processed one after another in the order they are received. If a queue already has a NewTick event, or this event is currently being processed, then the new NewTick event is not placed in the queue of the MQL5 program. Similarly, if ChartEvent is already enqueued, or this event is being processed, no new event of this kind is enqueued. The timer events are handled the same way — if the Timer event is in the queue or being handled, the new timer event is not enqueued. 


Looking forward to your reply ;-)

 
Ok. I am the blindfold ;) Thank you for this worthful information. It explains a misbehaviour of my EA which happened very rarely and now I know how to solve this. 
 
hehehe, no worries mate :D I only got it after Alain pointed me to that page yesterday
 

So then I owe you guys something :)

To enable full interaction during strategy tester I implemented own functions which create own chart events in a second/own queue, where this problem never occured. And on live accounts it happened only on VPS systems where CPU is shared. So my reason is simply to avoid the original OnChartEvent() and to rely on my own stuff. Ok you dont know what I am talking about but you guys definetly made my day! 

 

Yup, we do know what you are talking about, it takes a custom solution and as I said earlier, we have already discussed it on the forum a few days ago so it's no great secret Doerk.

Though it would have been nice of you to share your findings with the rest of the forum, just as you have asked for assistance from the forum members in the past.....