Download MetaTrader 5

Backtesting Multi-Currency EA

To add comments, please log in or register
Andriy Moraru
1261
Andriy Moraru  

I'm currently backtesting a multi-currency-pair EA in the MT5 Strategy Tester and I get different results when attaching it to different currency pairs. The EA trades on AUDUSD and GBPCHF.

When I attach it to AUDUSD it gets 10k profit.

When I attach it to GBPCHF it gets more than 30k profit.

When I attach it to USDCHF (I thought OnTick() function will react on both AUDUSD and GBPCHF changes when following USDCHF) it gets about 17k profit.

Is it the problem of using the OnTick() function? Or is there some hidden problem in backtesting multi-currency EAs? Or is it just some mess in my code?

T Wawang R
322
T Wawang R  
enivid:

I'm currently backtesting a multi-currency-pair EA in the MT5 Strategy Tester and I get different results when attaching it to different currency pairs. The EA trades on AUDUSD and GBPCHF.

When I attach it to AUDUSD it gets 10k profit.

When I attach it to GBPCHF it gets more than 30k profit.

When I attach it to USDCHF (I thought OnTick() function will react on both AUDUSD and GBPCHF changes when following USDCHF) it gets about 17k profit.

Is it the problem of using the OnTick() function? Or is there some hidden problem in backtesting multi-currency EAs? Or is it just some mess in my code?

better, if you copy the code here.. maybe it wll help.
Andriy Moraru
1261
Andriy Moraru  
The code shouldn't really matter. Why would the Tester make any difference for the attached currency pair if all trading is done on two predefined currency pairs and all trading is also performed on new bar opening, not every tick.
baq
84
baq  
enivid:

The code shouldn't really matter. Why would the Tester make any difference for the attached currency pair if all trading is done on two predefined currency pairs and all trading is also performed on new bar opening, not every tick.

Isn't the "on tick" function only for the chart currency? I would say for 99% it is. I guess you can create an infinite loop refreshing quotes every second or so to get more accurate ticks. This would change the whole structure of an application though.

investeo
4104
investeo  
enivid:

The code shouldn't really matter. Why would the Tester make any difference for the attached currency pair if all trading is done on two predefined currency pairs and all trading is also performed on new bar opening, not every tick.

Maybe you should try OnBookEvent() instead of OnTick()? - OnTick() is triggered only when current symbol tick arrives.

OnBookEvent

The OnBookEvent() function is the BookEvent handler. BookEvent is generated for Expert Advisors only when Depth of Market changes. It must be of the void type and have one parameter of the string type:

void OnBookEvent (const stringsymbol);

To receive BookEvent events for any symbol, you just need to pre-subscribe to receive these events for this symbol using the MarketBookAdd() function. In order to unsubscribe from receiving the BookEvent events for a particular symbol, call MarketBookRelease().

Unlike other events, the BookEvent event is broadcast. This means that if one Expert Advisor subscribes to receiving BookEvent events using MarketBookAdd, all the other Experts Advisors that have the OnBookEvent() handler will receive this event. It is therefore necessary to analyze the name of the symbol, which is passed to the handler as the const string& symbol parameter.

trendick
47
trendick  

I experience the same problem: Backtesting a multi-currency EA I get totally different behavior depending on which symbol I select in the strategy tester panel.

This is extremely bothersome. Rosh? Anybody? can you comment please?

Even if the on tick applies only to the selected chart, both envid and myself are operating on the opening of a new bar. In my case I use daily bars so even if the open tick of the new bars in the various currencies occur at different times no such drastic differences as I experience should happen.

I'm not including my EA due to obvious reasons.  Let's see if we have the same problem with the EA that was published here: https://www.mql5.com/en/articles/105.

I would be very happy to hear from anybody who is having success inconstructing a multi-currency EA and in particular, not suffering from this discrepancy.

Creating an Expert Advisor, which Trades on a Number of Instruments
  • 2010.07.08
  • Nikolay Kositsin
  • www.mql5.com
The concept of diversification of assets on financial markets is quiet old, and has always attracted beginner traders. In this article, the author proposes a maximally simple approach to a construction of a multi-currency Expert Advisor, for an initial introduction to this direction of trading strategies.
Andriy Moraru
1261
Andriy Moraru  
investeo:

Maybe you should try OnBookEvent() instead of OnTick()? - OnTick() is triggered only when current symbol tick arrives.

OnBookEvent

The OnBookEvent() function is the BookEvent handler. BookEvent is generated for Expert Advisors only when Depth of Market changes. It must be of the void type and have one parameter of the string type:

void OnBookEvent (const stringsymbol);

To receive BookEvent events for any symbol, you just need to pre-subscribe to receive these events for this symbol using the MarketBookAdd() function. In order to unsubscribe from receiving the BookEvent events for a particular symbol, call MarketBookRelease().

Unlike other events, the BookEvent event is broadcast. This means that if one Expert Advisor subscribes to receiving BookEvent events using MarketBookAdd, all the other Experts Advisors that have the OnBookEvent() handler will receive this event. It is therefore necessary to analyze the name of the symbol, which is passed to the handler as the const string& symbol parameter.

I tried using OnBookEvent() but it simply isn't working (at least in backtesting). I've used MarketBookAdd() in the OnInit() function for both my pairs.
trendick
47
trendick  

Here is an example. Using the TEMA EA from https://www.mql5.com/en/articles/105 We get the following different behaviors.

All you need is the EA  exp_tema_en.mq5 and the indicator  multistochastic_en.mq5

In this example I used the attached param set file. The EA trades the pairs EURUSD, USDCHF and USDJPY (with these parameters).

When you attach it to EURUSD you get

Equity when attached to EURUSD

when attaching to USDCHF you will get

usdchf

Then, with USDJPY we get

usdjpy

and better yet, when running the EA on AUDUSD the result

audusd

Same EA, same timeframe (H1), same traded pairs, same dates (2009.01.01-2009.03.01). 

Is that the way it is supposed to be? and if it does, can someone tell us what's the meaning of this?

Are we really ready to multi-currency backtesting/optimization?

Creating an Expert Advisor, which Trades on a Number of Instruments
  • 2010.07.08
  • Nikolay Kositsin
  • www.mql5.com
The concept of diversification of assets on financial markets is quiet old, and has always attracted beginner traders. In this article, the author proposes a maximally simple approach to a construction of a multi-currency Expert Advisor, for an initial introduction to this direction of trading strategies.
Alireza
133
Alireza  
trendick:

Here is an example. Using the TEMA EA from https://www.mql5.com/en/articles/105 We get the following different behaviors.

All you need is the EA  exp_tema_en.mq5 and the indicator  multistochastic_en.mq5

In this example I used the attached param set file. The EA trades the pairs EURUSD, USDCHF and USDJPY (with these parameters).

When you attach it to EURUSD you get


when attaching to USDCHF you will get


Then, with USDJPY we get

and better yet, when running the EA on AUDUSD the result

Same EA, same timeframe (H1), same traded pairs, same dates (2009.01.01-2009.03.01). 

Is that the way it is supposed to be? and if it does, can someone tell us what's the meaning of this?

Are we really ready to multi-currency backtesting/optimization?




Hi,I had the same problem(different results), but solved it with the IsNewBar()

I agree with baq, so what should we do?get the quotes and this function does

Only if IsNewBar(some symbol) then blah blah blah

for my EA i got the same results attaching to different symbols.

the article which i got the function from is here: https://www.mql5.com/en/articles/105

Creating an Expert Advisor, which Trades on a Number of Instruments
  • 2010.07.08
  • Nikolay Kositsin
  • www.mql5.com
The concept of diversification of assets on financial markets is quiet old, and has always attracted beginner traders. In this article, the author proposes a maximally simple approach to a construction of a multi-currency Expert Advisor, for an initial introduction to this direction of trading strategies.
trendick
47
trendick  
Ali2e7a:

Hi,I had the same problem(different results), but solved it with the IsNewBar()

I agree with baq, so what should we do?get the quotes and this function does

Only if IsNewBar(some symbol) then blah blah blah

for my EA i got the same results attaching to different symbols.

the article which i got the function from is here: https://www.mql5.com/en/articles/105

Ali, the example I mentioned above is the EA you refer to, which is the source of the IsNewBar() function you mentioned, and already uses it.

How do you explain this? 

trendick
47
trendick  

See also the Multi-currency synchronization thread at https://www.mql5.com/en/forum/1520.

Multi-Currency synchronization
  • www.mql5.com
Here some tests results and below details:.
1234
To add comments, please log in or register