just a guess, but i would probably put in OnTick, a counter, and each tick adds 1 to this counter, and then in OnTimer, would be monitoring and recording time when each counter has changed. When XX ms has passed, then, the ea takes a "break" or just "return" after a Print msg, or(else) the counter is added to by 1.
This is wrong, because MQL5 programs are single-threaded, so if a lengthy OnTick is being processed, there can be no any other events, including pending OnTimer, executed in parallel.
The solution is to check timeout manualy in the EA itself, for example, in the loop condition if it's running a loop, in the same way as MQL5 program should normally check _IsStopped flag for prompt termination if requested by a user.
What you can do is count the miliseconds at the start of your process and the at the end and substract in order to know how many have passed, run this code, perhaps it helps you:
void OnTick() { //--- ulong us = GetMicrosecondCount(); ulong ms = us / 1000; Print("MicroSeconds: ", ms); }
It prints the quantity of ms that have passed since the start of the EA.
Something like this can help. : )
What you can do is count the miliseconds at the start of your process and the at the end and substract in order to know how many have passed, run this code, perhaps it helps you:
It prints the quantity of ms that have passed since the start of the EA.
Something like this can help. : )
Hmmmm, I would add the time calculator at different parts of the process, one at the start, at the middle, etc...
and adding an if function at each step, something like this:
void OnTick() { //--- bool process = true; while(process) { ulong inicTime = GetMicrosecondCount(); // Process 1 ulong secTime = GetMicrosecondCount(); Print(secTime - inicTime); if(secTime - inicTime> 20)break; // Process 2 ulong thrTime = GetMicrosecondCount(); Print(thrTime - inicTime); } }
Don't have enough intertnet to check this parts:
if(thrTime - inicTime > 20)break;
For the uints, etc...
But I think this solves the problem. : )
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
How to do, let say EA usually take 10 ms and i want to set if EA taking more than 20ms during onTick operation exit/break whole operation in middle and start again in next tick.