Stefano Cerbioni:
Hello everyone,
I’m developing a multi-application system that communicates with MT5.
Right now, the architecture is such that MT5 runs multiple Expert Advisors (EAs) to interact with different applications via TCP or other IPC mechanisms.
The problem I face is the execution delay caused by MT5's OnTick event.
If an EA is attached to a symbol that receives ticks infrequently (low liquidity, off-market hours), OnTick will not trigger for long periods of time.
This means that even if an external application sends an order to MT5, the EA cannot process it immediately unless a new tick arrives.
For example:
I have EA1 attached to EURUSD, EA2 attached to XAUUSD, etc.
If XAUUSD is not trading at that moment (few ticks), EA2 will remain idle until a new tick arrives.
This creates unacceptable latency for certain trading strategies that require immediate execution regardless of tick arrival.
I have considered:
Using EventSetTimer() with a short interval — but MT5 does not guarantee stable sub-second timers and this consumes a lot of CPU.
Running multiple EAs on different high-liquidity symbols — but this increases complexity and resource usage.
Writing a DLL/plugin in C++ to simulate ticks or force EA execution — but this is complex and undocumented.
My question for the community:
Has anyone found a clean and reliable workaround to force an EA to execute instantly in MT5, even when the symbol receives no new ticks?
Is there a known method, plugin, or trick to bypass this OnTick limitation without severely affecting performance?
Thanks in advance for your insights.
Use custom events.
What is a stable sub-second interval for your use case ?
However, I understand MT5 has limitations for sub-second timers, and using very short intervals could heavily impact performance. For that reason, I’m more interested in exploring a robust alternative that avoids relying on constant polling timers.
The custom events approach you mentioned seems promising, as it could allow triggering EA actions immediately regardless of tick arrival. This would avoid the latency caused by low liquidity or quiet market periods, and could be more efficient than using EventSetTimer at very short intervals.
I would be interested in hearing if others have successfully implemented custom events for this purpose, and what interval or method they consider stable for near-real-time execution in MT5.
Thank you for your suggestion. Regarding your question about a stable sub-second interval — my use case requires near-instant execution, ideally below 200 milliseconds, because certain trading strategies I work on need minimal latency.
However, I understand MT5 has limitations for sub-second timers, and using very short intervals could heavily impact performance. For that reason, I’m more interested in exploring a robust alternative that avoids relying on constant polling timers.
The custom events approach you mentioned seems promising, as it could allow triggering EA actions immediately regardless of tick arrival. This would avoid the latency caused by low liquidity or quiet market periods, and could be more efficient than using EventSetTimer at very short intervals.
I would be interested in hearing if others have successfully implemented custom events for this purpose, and what interval or method they consider stable for near-real-time execution in MT5.
I’m developing a multi-application system that communicates with MT5.
Right now, the architecture is such that MT5 runs multiple Expert Advisors (EAs) to interact with different applications via TCP or other IPC mechanisms.
The problem I face is the execution delay caused by MT5's OnTick event.
If an EA is attached to a symbol that receives ticks infrequently (low liquidity, off-market hours), OnTick will not trigger for long periods of time.
This means that even if an external application sends an order to MT5, the EA cannot process it immediately unless a new tick arrives.
It looks like you want to implement the system other way round.
In MT5 develop a service which has to be connected via WebSocket to your external application/server, the service will run an infinite loop with blocking reading/waiting data from the server. As soon as the server sends a packet (an order or other command) the service will awake and dispatch the data to appropriate chart with EA via custom event instantly.
It looks like you want to implement the system other way round.
In MT5 develop a service which has to be connected via WebSocket to your external application/server, the service will run an infinite loop with blocking reading/waiting data from the server. As soon as the server sends a packet (an order or other command) the service will awake and dispatch the data to appropriate chart with EA via custom event instantly.
- 2011.02.18
- www.mql5.com
So you mean I could achieve this by adding my server URL in the WebRequest settings under the MT5 options? not understund good
Not a WebRequest, but websocket connection on top of the Sockets API. Your server should implement websocket server part (most production servers support this feature out-of-the-box). And yes, you need to add the server to the settings anyway.
The algotrading book provides an example of websocket implementation in MQL5.
- www.mql5.com
- 2024.02.11
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I’m developing a multi-application system that communicates with MT5.
Right now, the architecture is such that MT5 runs multiple Expert Advisors (EAs) to interact with different applications via TCP or other IPC mechanisms.
The problem I face is the execution delay caused by MT5's OnTick event.
If an EA is attached to a symbol that receives ticks infrequently (low liquidity, off-market hours), OnTick will not trigger for long periods of time.
This means that even if an external application sends an order to MT5, the EA cannot process it immediately unless a new tick arrives.
For example:
I have EA1 attached to EURUSD, EA2 attached to XAUUSD, etc.
If XAUUSD is not trading at that moment (few ticks), EA2 will remain idle until a new tick arrives.
This creates unacceptable latency for certain trading strategies that require immediate execution regardless of tick arrival.
I have considered:
Using EventSetTimer() with a short interval — but MT5 does not guarantee stable sub-second timers and this consumes a lot of CPU.
Running multiple EAs on different high-liquidity symbols — but this increases complexity and resource usage.
Writing a DLL/plugin in C++ to simulate ticks or force EA execution — but this is complex and undocumented.
My question for the community:
Has anyone found a clean and reliable workaround to force an EA to execute instantly in MT5, even when the symbol receives no new ticks?
Is there a known method, plugin, or trick to bypass this OnTick limitation without severely affecting performance?
Thanks in advance for your insights.