Problem: EA execution delay when symbol has low tick frequency in MT5 — any workaround?

 
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.
 

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.

What is a stable sub-second interval for your use case ?

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.

 
Alain Verleyen #:
What is a stable sub-second interval for your use case ?
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.
 
Stefano Cerbioni #:
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.
MT5 is perfectly fine with 100 ms timer, maybe even lower but I have experience only up to 100ms.
 
Stefano Cerbioni:
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.

 
Stanislav Korotky #:

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.

So you mean I could achieve this by adding my server URL in the WebRequest settings under the MT5 options? not understund good 
 
So is this a multi-symbol problem and you are running into the ticks on one chart but not on the other? Either way you should probably be using custom events for this. Also its a little confusing how you are doing this which is why Stanislav said you want to implement the system the other way around. I don't have any experience using custom events to trigger stuff outside of MT5 but I run all my multisymbol EAs based off custom chart events in the exact same manner as described in this article: https://www.mql5.com/en/articles/234 perhaps you can figure out something similar or someone else smarter than me will suggest something
The Implementation of a Multi-currency Mode in MetaTrader 5
The Implementation of a Multi-currency Mode in MetaTrader 5
  • 2011.02.18
  • www.mql5.com
For a long time multi-currency analysis and multi-currency trading has been of interest to people. The opportunity to implement a full fledged multi-currency regime became possible only with the public release of MetaTrader 5 and the MQL5 programming language. In this article we propose a way to analyze and process all incoming ticks for several symbols. As an illustration, let's consider a multi-currency RSI indicator of the USDx dollar index.
 
Stefano Cerbioni #:
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.

Documentation on MQL5: Network Functions
Documentation on MQL5: Network Functions
  • www.mql5.com
MQL5 programs can exchange data with remote servers, as well as send push notifications, emails and data via FTP. The Socket* group of functions...
 
Sorry, but I was looking into the WebSocket approach because it seems to be the fastest option available on MT5. However, it’s obviously a complete nightmare of biblical proportions just to exchange two simple pieces of data between MT5, a server, a DLL, and my own application (I even wonder why we don’t throw something else into the mix too :D). 

More importantly, I keep asking myself: why don’t MetaTrader developers provide even minimal APIs to send orders and retrieve data about current and historical trades? Are we really asking for too much? 

That said (sorry for the frustration), I noticed that in this thread it’s clearly stated that WebSockets—or rather, DLLs in general—cannot use callbacks:   

    “DLL functionality in MQL is limited in some aspects. It is somewhat 'sandboxed' so callbacks are not possible. Instead, consider polling from the MQL program side.”
     

So before going any further, I’d like to ask:
Is it actually possible to work without relying on OnTick or EventSetTimer, while still achieving response times around 200 ms without noticeable lag?   

And secondly: Are there any minimal, free, and open-source examples—including both server-side and DLL components—that already implement such a solution?
Callback to MQ5 code from DLL - How to use a DLL in my MQ5 terminal?
Callback to MQ5 code from DLL - How to use a DLL in my MQ5 terminal?
  • 2024.02.11
  • www.mql5.com
This dll should be able to send signals to my mt5 terminal. But it does not seem possible to pass functions as parameters in mq5, neither was i able to get the address of a mq5 function. If that's the case, then you should use a semaphore to make the dll sync with the ex5 executable