Yes, for a single EA to trade multiple symbols at the same time, it can be quite complex.
You will not be able to depend on the OnTick event handler because that only handles the current chart symbol.
Forum on trading, automated trading systems and testing trading strategies
Fernando Carreiro, 2023.01.10 13:54
Ok, then that is the problem!
If you only react on OnTick(), then you are reacting only to ticks from the current symbol. You will miss all tick events from the other symbols.
Also, if your event handler takes to long then you will also miss ticks from the current symbol too.
To resolve the issue you will need to make use of a combination of OnTick() and OnTimer() or use a slave indicator to send out a custom chart events to signal tick events on other symbols (see below).
And to access all the tick data without missing any, you will need to use CopyTicks() function.
Also read the following ...
Forum on trading, automated trading systems and testing trading strategies
Can a buffer update in the middle of two commands?
Fernando Carreiro, 2022.04.27 13:11
The OnTick() event handler gets called on every new tick for the current symbol only, but what will you do if there are no new ticks for the current symbol, but there have been ticks for other symbols you are trading with the EA?
By using the OnTimer() in combination with OnTick(), set at a regular interval, you still get to query the current state of other symbols, even if the current symbol is inactive. Consider it a "heartbeat" function or protocol.
By using EURUSD as your primary chart, you will have plenty of tick activity since its one of the most active symbols, but it also has lull periods compared to other symbols, or not trade at all compared to some other symbols. What if you are also trading BitCoin on your EA which trades during the weekend, but EURUSD does not?
By using the OnTimer() as well, your EA will continue to query all the other symbols and act accordingly even if the primary chart is on pause.
The Implementation of a Multi-currency Mode in MetaTrader 5
Konstantin Gruzdev, 2011.02.18 17:58
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.
That does not matter, You will still need to trigger that event and the current chart OnTick alone may miss it.
You will also have to align the bar data for each symbol because there may be gaps in time on some symbols compared to others, causing the data to be misaligned.
It is more complex than you might originally think.
Is it difficult? Is a complete rewrite of the code required?
I am asking for my EA seller. Because i want his EA can trade all 28 pairs at once.
- Yes
- It's unnecessary if the EA filters by symbol, or you change the magic number. Just put it on a second chart. Done.
I can relate to that. That was the reason I made a few multi-currency EAs myself, mainly for the back-testing.
However, I coded them, so that I could have them trade only on the current chart, when I use them for live trading, and disabling the extra multi-symbol logic so that they run more efficiently.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Is it difficult? Is a complete rewrite of the code required?
I am asking for my EA seller. Because i want his EA can trade all 28 pairs at once.