Multicurrency EAs driven by asynchronous events (OnTimer, OnChartEvent, multiple tick streams) are not deterministic in distributed MT5 Strategy Tester runs.
For reproducible results, the most stable approach is a bar-driven engine (e.g. M1) with explicit history synchronization and logic executed only on bar changes.
A "heartbeat" only makes sense if implemented as a fully controlled custom symbol; if it depends on real ticks, the issue remains.
There are tons of articles and blogs about the many issues with multicurrency EAs. And remarkably little clarity over the best practice. Let me summarize some of the problems I have encountered:
For the longest of times, I have used ISpy in combination with OnChartEvent for multicurrency EAs, until recently when I encounter that the results I was getting from a farm of agents were different between simulations. That was a pain to debug, and came to discover that the problem is that when many pairs are loaded, this overruns the EA with events, and it actually bypasses/ never runs some events. That was a crazy finding, as basically as a way to avoid overload, the EA bypasses commands, this is a major concern over this solution specially at critical times like news events.
A solution was OnTimer, another deceiving tool when using strategy tester, it turns out that on strategy tester on Timer is set by the tick data you set in the main chart. Results on OnTimer were very unreliable when running the EA optimization on agents from a farm. I was not able to figure out why agents set different OnTimers, but the same multicurrency ea produces exactly the same result in a local machine but varying results when run in agents.
What do you mean ?
I am using OnTimer without problem, though it could depends how you are using it ?
Then came the use of OnTick (using as very liquid pair as the base chart, like BTCUSD), and implementing an internal OnNewBar (to check all pairs every minute) to then loop over all pairs. This reduced considerably the use of resources, but remarkably the results were different than if I use the ISpy (reliably but heavy and error prone when many tick arrive simultaneously).
So do not trade multiple currencies in one EA.
-
You can't use any {MT4: predefined variables, MT5: predefined variables,}
-
A multi-asset EA runs in one thread so that one asset blocks all the others, while each EA for a single asset runs in its own thread,
-
Must poll (not OnTick, unless you use specific indicators)
The Implementation of a Multi-currency Mode in MetaTrader 5 - MQL5 Articles (2011) -
and usually other problems, e.g. A problem with iBarShift - MQL4 programming forum - Page 2 (2016)
-
You must handle History {MT4:4066/4073 errors: Download history in MQL4 EA - MQL4 programming forum, MT5: Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5.}
-
Code it to trade the chart pair only. Look at the others if you must. Don't assume that Time[i] == iTime(otherPair, TF, i) always use iBarShift.
Then put it on other charts to trade the other pairs. Done.
Spy with discarding ticks on a too close price basis (for instance 1 pip absolute distance between ticks) and buffering chart events should work
It's not reliable.
At least if you are using 20 or more symbols, maybe with less it could work, I didn't try.Using a heartbeat symbol is actually a pretty clever workaround, because it forces a consistent timing source and avoids the chaos of event overload. The bigger challenge is that multicurrency EAs will always behave differently across agents unless every feed, tick arrival, and timer trigger is perfectly synchronized. In practice, the most reproducible results usually come from a single‑chart OnTick loop with strict bar‑based logic and minimal reliance on event‑driven functions.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
There are tons of articles and blogs about the many issues with multicurrency EAs. And remarkably little clarity over the best practice. Let me summarize some of the problems I have encountered:
For the longest of times, I have used ISpy in combination with OnChartEvent for multicurrency EAs, until recently when I encounter that the results I was getting from a farm of agents were different between simulations. That was a pain to debug, and came to discover that the problem is that when many pairs are loaded, this overruns the EA with events, and it actually bypasses/ never runs some events. That was a crazy finding, as basically as a way to avoid overload, the EA bypasses commands, this is a major concern over this solution specially at critical times like news events.
A solution was OnTimer, another deceiving tool when using strategy tester, it turns out that on strategy tester on Timer is set by the tick data you set in the main chart. Results on OnTimer were very unreliable when running the EA optimization on agents from a farm. I was not able to figure out why agents set different OnTimers, but the same multicurrency ea produces exactly the same result in a local machine but varying results when run in agents.
Then came the use of OnTick (using as very liquid pair as the base chart, like BTCUSD), and implementing an internal OnNewBar (to check all pairs every minute) to then loop over all pairs. This reduced considerably the use of resources, but remarkably the results were different than if I use the ISpy (reliably but heavy and error prone when many tick arrive simultaneously).
In theory, all we need during back-test and live trading is a reliable timer that we can use to check at specific time intervals the rates of pairs to trade. That brought me to this idea of creating a heartbeat currency pair. A fake pair that has 1 tick per minute, and this is used as the base of the ea. Basically it will reliably check every certain amount of time the data in pairs over a loop. What people think of this idea. Any other suggestions on how to generate reproducible results from optimizations in multicurrency EAs, while considering the effects of backtesting with agents?