What is the best suggestion for multicurrency EAs: OnTick, OnTimer, onChartevent?

 

While working with multi-currency EAs, most commonly one has a unique EA that is applied over to multiple currencies. In theory, there is an infinite loop, running the same operations over data from multiple currency pairs. While studying how to do this, I came across three alternative suggestions on where to run this loop, none of which I found to be perfect, and have been rarely discussed and I wanted to ask your opinion on where is the the best place to run the infinite loop:

1. OnTick. The problem of ruing the template here, is that the loop is only run when there is a tick on the pair displayed in the chart. If there is tick in another pair this will not be processed.

2. OnTimer. The problem here is that you will be doing loops over pairs that may have not changed during the time lapse of the timer (losing computing resources), or massive changes could happen in between time intervals, and they will be noticed/processed only at the end of the timer (although one could use smaller settimer , e.g. every 60 seconds),

3. onChartevent. Here an indicator like iSpy is deployed on each pair chart,  which will transmit the change in tick on any pair to the main chart for processing. This appears to be the best one, and in my own experience it worked well when in a local computer, but fall apart when deployed in the MQL5 VPS, as tge many charts deployed reach critical RAM allocations, making the iSpy indicator very slow and bypassing signals at critical times.

 
Camilo Mora:

While working with multi-currency EAs, most commonly one has a unique EA that is applied over to multiple currencies. In theory, there is an infinite loop, running the same operations over data from multiple currency pairs. While studying how to do this, I came across three alternative suggestions on where to run this loop, none of which I found to be perfect, and have been rarely discussed and I wanted to ask your opinion on where is the the best place to run the infinite loop:

1. OnTick. The problem of ruing the template here, is that the loop is only run when there is a tick on the pair displayed in the chart. If there is tick in another pair this will not be processed.

2. OnTimer. The problem here is that you will be doing loops over pairs that may have not changed during the time lapse of the timer (losing computing resources), or massive changes could happen in between time intervals, and they will be noticed/processed only at the end of the timer (although one could use smaller settimer , e.g. every 60 seconds),

3. onChartevent. Here an indicator like iSpy is deployed on each pair chart,  which will transmit the change in tick on any pair to the main chart for processing. This appears to be the best one, and in my own experience it worked well when in a local computer, but fall apart when deployed in the MQL5 VPS, as tge many charts deployed reach critical RAM allocations, making the iSpy indicator very slow and bypassing signals at critical times.

If you are going to predict more than 100-200 or more points in each pair, it doesn't matter how small your time in Ontimer is. Your strategy will be robust and will work even every 5 minutes as small changes are not necessary for prediction.

After all, in time series analysis, you analyze the data set, not just the last milliseconds between each tick.

I always suggest using candle (1) in 5 minutes, using OpenPrices and OnTimer(300s) for multicurrency or single pair.

This will make the strategy solid and will work in OnTick, in Milliseconds and in OHLC as well as you can also extrapolate it to other MT5 scenarios, eg python, LLM's, etc.

At the same time, you will save resources on optimizations and the backtests for you to analyze your strategy will be faster.

It is different if you work with HFT, in that case milliseconds are necessary.

 

OnTick is only the current symbol. OnChart is only the current symbol, OnTimer means you miss ticks. None will help you.

I recommend: Do not trade multiple currencies in one EA.

  1. You can't use any {MT4: predefined variables, MT5: predefined variables,}

  2. 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,

  3. Must poll (not OnTick, unless you use specific indicators)
              The Implementation of a Multi-currency Mode in MetaTrader 5 - MQL5 Articles (2011)