Convert an MT5 EA from single to a multi-currencies EA

 

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.

 
Kwok Fung Chan: 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, 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

Never miss Ticks

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.

Articles

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.
 
Fernando Carreiro #:

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.

The EA only trade 15Minutes chart when new candle open.

 
Kwok Fung Chan #: The EA only trade 15Minutes chart when new candle open.

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.

 
Kwok Fung Chan:

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.

  1. Yes
  2. It's unnecessary if the EA filters by symbol, or you change the magic number. Just put it on a second chart. Done.
 
William Roeder #:
  1. Yes
  2. It's unnecessary if the EA filters by symbol, or you change the magic number. Just put it on a second chart. Done.

yes i can put the ea to all 28 pairs but i can't backtest properly if like that.

 
Kwok Fung Chan #: yes i can put the ea to all 28 pairs but i can't backtest properly if like that.

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.