Search code examples
mql5metatrader5

Which event is called first? OnTick() or OnTimer()?


If I am processing OnTick events as well as OnTimer events, is there a preference in the queue? When calculating time sensitive algorithms in seconds, I am wondering whether it is easier to write a whole EA inside OnTimer to avoid event handling issues.


Solution

  • OnTimer is the scheduled call. If your current OnTimer call takes long to process, the succeeding OnTimer might be skipped. Same with OnTick. If suppose the EA starts at 00:00:00.021 with EventSetTimer(1);, then the EA will call it each second at 21-th millisecond( well, some people says that is not always true but it is acceptable in most cases). At the same time it is possible that you receive more ticks during a second, or no ticks at all. If some action is important, OnTimer() may help with that.
    What is the criteria that you should use OnTimer()? In MT4 one of the examples is using renko charts(in real time, for tests the call is off in MT4). For both MT4&5 OnTimer() is fine if you work with multicurrency expert. You may control OnTick of one symbol but not for both/all, OnTimer is called even if new tick did not arrive.