I need YOUR HELP

 

Hi Everybody,

I'm facing an issue with an EA where I want to enter simultaneous orders (sell/ buy) in different currency pairs. I understand that MetaTrader4 has limitations and normally cannot perform backtesting of more than one single currency pair.

Are you aware about any possible solution to overcome the above limitation? or can you perhaps address us to people who could help.
Please advise me.
Many thanks for your cooperation.

Fabio

 

Fabio your post appears to entail two seperate questions/issues.

I want to enter simultaneous orders (sell/ buy) in different currency pairs


Help me understand what you view "enter simultaneous" to mean. Do you mean to say the orders for opening trades are placed/executed simultaneously in time (exact same nanosecond) or you mean "opened successively in time with as little time delay between the opening as possible"? One is not possible, the other is possible.

cannot perform backtesting of more than one single currency pair

Strategy tester can operate on more than one currency at a time, you must explicitely declare what symbol is being used in the indicators as well as the marketinfo and order placement functions. But since MT4 is tick driven, meaning a new tick must come in (or be simulated in strategy tester) on the currency pair being tested you do lose is the ability to have trade activity base off of ticks in the other currency pairs.

Say you backtest on the EURUSD (or assign your EA to the EURUSD chart in forward test) and your EA is coded to trade both the EURUSD and the USDJPY. As ticks come in to EURUSD your code evaluates the price data of both EURUSD and USDJPY, no problems. But you are missing opportunities to trade on USDJPY ticks which might be occurring while the EURUSD is seeing no market activity. Does this make sense to you?


(edit: the above struck-out text is completely wrong, absolutely no idea what I was thinking about when I drafted it, see gordon's response below)

 

Strategy tester can operate on more than one currency at a time, you must explicitely declare what symbol is being used in the indicators as well as the marketinfo and order placement functions. But since MT4 is tick driven, meaning a new tick must come in (or be simulated in strategy tester) on the currency pair being tested you do lose is the ability to have trade activity base off of ticks in the other currency pairs.

Say you backtest on the EURUSD (or assign your EA to the EURUSD chart in forward test) and your EA is coded to trade both the EURUSD and the USDJPY. As ticks come in to EURUSD your code evaluates the price data of both EURUSD and USDJPY, no problems. But you are missing opportunities to trade on USDJPY ticks which might be occurring while the EURUSD is seeing no market activity. Does this make sense to you?


Is there a way to make backtests on multiple pairs, just like attaching the same EA to multiple charts?
Without loosing any trade opportunities or anything else.

 
msbusinessil wrote >>


Is there a way to make backtests on multiple pairs, just like attaching the same EA to multiple charts?
Without loosing any trade opportunities or anything else.


Can it be done in straightforward fashion ? No.

Can it be done given a little creative programming and effort? Yes.

One way to do it is to create your own synthetic backtesting instrument which contains all the tick-time events for all pairs involved and use strategy tester merely as a means of iterating thru these ticks while using each synthetic tick as a means to query the actual historical datafile's pricing data at that relevant point in time.

The sky is the limit when it comes to backtesting once you build your own virtual strategy tester that lives and operates within the MT4 strategy tester. I use strategy tester as a kind of "front-end" to my customized strategy tester which then enables me to compute things like the proper rollover/swap rates (based on historical data I collected from brokers over time) that should have been levied on my trades, etc.

You can do a lot with that init() and deinit()...whether there is sufficient value to be generated by going to those lengths is a question worth asking before diving in.

IMO it was not, better to develop agnostic strategies that are not dependent on the nuances and subtleties of brokers and their platforms. Sure you leave hypothetical backtesting earnings on the table, an process that avoids over-optimization will do this, but I'm no longer interested in creating EA's that turn 1k into 1m in 3 months. That said, I would not deny others the knowledge of what can be done nor would I discourage them from pursuing that direction of strategy development, who knows how much I missed when I went there.

 
1005phillip:
Strategy tester can operate on more than one currency at a time, you must explicitely declare what symbol is being used in the indicators as well as the marketinfo and order placement functions.

You must have a mix up... The Tester can operate on one currency only at a time. Attempting to read other symbol's data with MarketInfo() will result in ERR_FUNCTION_NOT_ALLOWED_IN_TESTING_MODE(4059). Go ahead and try it, it doesn't work. The same goes for attempting to place orders on other symbols. Here are all the limitations in the Tester -> https://www.mql5.com/en/articles/1512.


p.s. MT5 has a multi-asset Tester and that's perhaps it's #1 selling point.

 
msbusinessil:

Is there a way to make backtests on multiple pairs, just like attaching the same EA to multiple charts?
Without loosing any trade opportunities or anything else.

If both EA's can be simulated independently (they rely on one currency only), then u can save their reports and "mix" them using a tool like this -> http://www.mt4i.com/mtidesktop.aspx. There should be scripts for this as well somewhere on the forum or in the code-base -> Search.

 
gordon wrote >>

You must have a mix up... The Tester can operate on one currency only at a time. Attempting to read other symbol's data with MarketInfo() will result in ERR_FUNCTION_NOT_ALLOWED_IN_TESTING_MODE(4059). Go ahead and try it, it doesn't work. The same goes for attempting to place orders on other symbols. Here are all the limitations in the Tester -> https://www.mql5.com/en/articles/1512.


p.s. MT5 has a multi-asset Tester and that's perhaps it's #1 selling point.



You are absolutely right, I just tested it. I'm at a total loss of words, I have vivid recollection of doing exactly what I described above (granted I "remember" it as being something I worked on some two years in my mental chronology of events, not as something I was doing yesterday) but maybe I just dreamed it to be true... MT3 didn't allow this by any chance, probably not. Regardless, yep what I wrote is completely not true regarding the backtesting of additional currency pairs at the same time. Now I just got to figure out what it was that I was doing 2yrs ago that had me convinced me I could/was doing what I attempted to post about...hmmm.

 
Fabio, you might find this article interesting -> 'Break Through The Strategy Tester Limit On Testing Hedge EA'. It describes a method to overcome the limitation, although not straight-forward and it has it's drawbacks. Anyway, there have been other possible solutions suggested in the forum over the years, you can try searching.

Phillip, this happens to us all. I have had my share of things I was absolutely sure about, but turned out to be the complete opposite of what they are.
 
gordon wrote >>
Fabio, you might find this article interesting -> 'Break Through The Strategy Tester Limit On Testing Hedge EA'. It describes a method to overcome the limitation, although not straight-forward and it has it's drawbacks. Anyway, there have been other possible solutions suggested in the forum over the years, you can try searching.

Phillip, this happens to us all. I have had my share of things I was absolutely sure about, but turned out to be the complete opposite of what they are.


Guys,
you are both great ;-) Phillip do not worry it happens often to me as well to remember something that I did long time ago and ... then after I mix the memories and so on ;-)

BTW, my first idea was indeed what's Phillip was proposing i.e a "Virtual Startegy tester " specially to enter the order "Sell / Buy" not necessarily simultaneously "at nanosecond" but with some gap between them. But it's NOT trivila task .

Gordon I'll read the article you pointed me out, hoping I can get some hint from it

Thanks again,
Fabio
 
Fabio wrote >>


Guys,
you are both great ;-) Phillip do not worry it happens often to me as well to remember something that I did long time ago and ... then after I mix the memories and so on ;-)

BTW, my first idea was indeed what's Phillip was proposing i.e a "Virtual Startegy tester " specially to enter the order "Sell / Buy" not necessarily simultaneously "at nanosecond" but with some gap between them. But it's NOT trivila task .

Gordon I'll read the article you pointed me out, hoping I can get some hint from it

Thanks again,
Fabio


thx for not giving me a hard time about my gaffe there!

Regarding the virtual strategy tester...this does work. You basically use the extisting strategy tester framework as a timeserver/tick-iterator and you create all the ordertrades/orderhistory in your own internal array (so placed orders are not actually placed in strategy tester, rather they are logged into your internal trade history array, initial price can be randomized to simulate slippage, etc) and you pull the relevant price data from csv files.

Export your hst file as csv, then read/import the data by currency pair as needed. If you want simulated tick values then make an EA that does nothing more in backtest beyond logging the strategy tester simulated ticks to a tick-log file.

If you have historical data regarding swap/rolloever rates you can calculate and apply a better estimate of the accumulating swap on your virtual open positions, etc. This also enables you to backtest on multiple currency pairs (I did not initially build mine for this purpose, but once I had it I did adapt it for this in time). Naturally the output results/screen in strategy tester remains blank since none of your orders were actually logged but you just create your own trade analyzer function that loads in the deinit() that processes the stats for your trade order history array and dumps the results into another csv file.

It may sound complicated, and at first it was a little daunting to implement, but it really is a rather simple thing to do once you have a good idea of what it is you aim to accomplish. It can be done with less than 2k lines of code, probably can be done with vastly less than that.
 
1005phillip wrote >>


thx for not giving me a hard time about my gaffe there!

Regarding the virtual strategy tester...this does work. You basically use the extisting strategy tester framework as a timeserver/tick-iterator and you create all the ordertrades/orderhistory in your own internal array (so placed orders are not actually placed in strategy tester, rather they are logged into your internal trade history array, initial price can be randomized to simulate slippage, etc) and you pull the relevant price data from csv files.

Export your hst file as csv, then read/import the data by currency pair as needed. If you want simulated tick values then make an EA that does nothing more in backtest beyond logging the strategy tester simulated ticks to a tick-log file.

If you have historical data regarding swap/rolloever rates you can calculate and apply a better estimate of the accumulating swap on your virtual open positions, etc. This also enables you to backtest on multiple currency pairs (I did not initially build mine for this purpose, but once I had it I did adapt it for this in time). Naturally the output results/screen in strategy tester remains blank since none of your orders were actually logged but you just create your own trade analyzer function that loads in the deinit() that processes the stats for your trade order history array and dumps the results into another csv file.

It may sound complicated, and at first it was a little daunting to implement, but it really is a rather simple thing to do once you have a good idea of what it is you aim to accomplish. It can be done with less than 2k lines of code, probably can be done with vastly less than that.


Phillip,
thx again for this explaination, but, indeed, it seems easy to say thta to do it ;-( . I mean for me it's not trivial ;-)
Moreover, just to complicate a bit, my real idea is to run the Startegy Tester with the Optmization ;-0

Anyway, at moment, I'll run a Strategy Tester with Optimization only on 1 currency pair, then I'll run another Optimization on the other pair and the I'll compare the result hoping to see some intersection area .

But, I still have a question : do you know if the Optimizer will call the "init" function for every iteration (pass) ?

Thx again
Fabio