Backtesting Limitation

Okay. So here’s the deal. I have an EA I’ve crafted that tests very well on many pairs over a long period of time. And it’s doing well in live forward testing currently.

But even at that, I don’t want to put all my eggs in one basket so to speak and trade just one currency. I would prefer to use much smaller lots over those many pairs.

Is there a way to test that to see what happens over time in an aggregate form, instead of just the one currency that the tester lets you select?

I think I could do it in Excel, but I know NOTHING about using it in conjunction with MT4. Could I run the tests, then import the data into Excel, or something along?

Any ideas? Or is there something in MT4 that I could use that would accomplish the same goal?

1 Like

Ultimately by design the MT4 Tester doesn’t accommodate what you seek to do (backtest multiple pairs testing in aggregate) but depending on the nature of your strategy you could take advantage of the fact that MQL allows you to access multiple currencies via it’s APIs despite the currency you have selected.

This post is a programming approach to trying to get MQL to use one strategy on multiple pairs. For the possibily of exporting report data to Excel on a per-pair-test basis, I’m not in Windows and I don’t use MT4 to check this out but CSV exporting sounds like a route to investigate.

Ok so anyways, basically everything in MQL revolves around the start() method.
This method is called when ever a tick is generated for the currency pair you’re observing.

If you’ve run the tester with EUR/USD, everytime a tick is generated by the pair, the MT4 engine calls start() which then allows your strategy to make enquires to find out the bid, ask, high, low, close, etc for the pair.

However, taking a look at the APIs, you can see that methods such as iClose, iBid, iAsk, iMarketData?, etc allow you to supply a Symbol(pair). So even though the start() was called for EUR/USD, you can still use the APIs to enquire about other pairs like USD/JPY, GBP/EUR and so on.

What makes an automated strategy execute efficiently is the event driven nature of the core engine call start() whenever something happens. This prevents one from having to write a strategy that spends every single microsecond checking bids, asks, closes and so on and testing for them for changes before running trading logic.

Bar based logic
If you have a strategy that reacts when a new bar starts (old bar just closed) on any timeframe, you can use the MT4 apis to monitor the bar counts on any pair (and timeframe) and when bar count changes occur for any one pair run trading logic on or with respect to the last closed bar (or indeed the current forming bar). As the checks being done are happening from within start(), this means that you can only interrogate other pairs when the pair you are observing generates a new tick.

Using a Script, as opposed to an EA for your logic prevents you using the Tester but if the logic is already tested, using a Script allows you to remove the start() restriction and control all the logic with bar count checks across multiple pairs and timeframes.

Tick based logic
If you have a strategy that reacts to new ticks then you have a fundamental problem in so far as the code will execute only when the pair being observed received a new tick and kicks off start(). Once this has happaned, nothing stops you from interrogating other pairs as per above. We know from looking at a watchlist that ticks come in across all pairs but not necessarily at the same time.

For live trading purposes this means we cannot use tick based strategies on multiple currencies from within the same start() method but must open up separate charts for each pair and attach the strategy accordingly.

For Tester (or even just MT4) purposes, we can generally presume that no one will be testing an ultra high frequency strategy that simply must capture and onserve every single tick-level price change so we can afford not to capture every sub-second tick but make do with working within say a maximum 5 second window [slow markets can generate no tick for even longer sometimes - so use the most liquid pair as the pair that generates calls to start()].

So what we do is let the start() method execute for the EURUSD tick that just came in and then use

double lastTickTime = MarketInfo(“SOME PAIR”, MODE_TIME)

to obtain the last tick time on any pair, compare that against the last check we made to see if there’s been a change, then kick off the logic while relying on MODE_ASK, MODE_BID, etc or some of the iFunctions below to get the info needed:

int iBars( string symbol, int timeframe)
int iBars(“SOME PAIR”, PERIOD_M5 | PERIOD_M15 | etc) gives you bar counts

double iClose( string symbol, int timeframe, int shift)
double iClose(“SOME PAIR”, PERIOD_M5 | PERIOD_M15 | etc, 0 | 1 | etc) give you the close price of any bar

iHigh, iLow, iOpen, iLowest, iHighest, iTime can all help to get information on any pair and timeframe.

Needless to say we can access indicator data for any pair and timeframe in much the same way.

As we’re looking at other pairs from within EURUSD generated start() calls there will be moments other pairs will tick and these will be missed by the logic until EURUSD itself ticks. But also as the EURUSD is the most liquid we increase the opportunity to get as many calls to start() such that the shortest time exists between any other pair’s tick and our ability to catch it.

Also, the time it will take to go through all the pairs will impact the core MQL engine as start() should complete work as quickly as possible (under 2 seconds) then return ready for the next tick. MQL doesn’t allow you to use threads or at least to get threads requires some Win32 DLL coding to force the operating system to give you them.

So if one seeks to coordinate multiple pairs trading in one strategy (keeping track of money management centrally across multiple pairs and trades for example) the underlying infrastructure risk inherent in MQL make this a risk to the capital being traded.

Global variables however (both in the trading logic and the system ones accessible to each logic instance attached to a chart) are a way we can share information across each instance to effect coordinated management otherwise the best thing to do is give each pair a copy of the strategy and allow each one to trade Equity/p of the money by opening Lots/p contracts where p is the number of observed pairs (and therefore the number of strategies running).

Bottom line
Doing your pair tests independently presents the least headache then pour over the results to derive your aggregate picture. If you normally risk X percent on one pair and know you will risk X/4 when looking at four pairs, do 4 tests and risk X/4 each time. Obviously this wont support dynamic situations where you might say X risk on pair 1, X/2 on pair 2 and X/4 on pair 3 as these trades arise but hey, this is Metatrader and MQL and everything is happening within a sandbox.

Alternative
JForex? :20:
Multi-threaded, Backtest multiple pairs 100% tick and spread modelling quality, OnTickEvent(), OnBarEvent(), OnAccountMessageEvent(), OnEconomicNewAnnouncementEvent(), access to every type of Java library and codebase in existence (database, email, SMS, GUI, PDF, encryption, networking), institutional liquidity, PAMM, Gold/Silver, CFDs in the works, blah, blah, blah.

Depends on what you’re up to and how complex it is or needs to be. Or rather how demanding your strategy and approach ultimately is of your platform.

1 Like

I know of no way to do this with mt4. there are some commercial back test programs that can do portfolio testing.
On a side I dont know how your EA is coded. if its not looking at account equity or account balance to close trades then running the back test on each currency pair separately will give you a pretty good idea of what will happen. you may want to make the EA use a fixed lot size in each back test also.

another alternative is the FXCM strat trader. You would need to recode the strat to C# but the back testing ability of that program makes mt4 look like a toy. Its free also.

First he becomes a member in 2009. Then attempts to slowly build up creditability and trust by posting 2500+ times.

Now he casually comes out and starts teasing all of us with how great and how much cash he has been making with his new “MT Holy Grail” EA.

What’s next, $97.00 for the signal-currency–lite version and $185.00 for the multi-currency- advanced mod?

Just like all the other freaking scam artist. :wink:

It doesn’t look at either balance, or equity just yet. Although that is in the works.

I’m more concerned with floating p/l numbers over an aggregate of pairs trading simultaneously. I’ll look into the FXCM deal. Dunno much about C#, but I guess it can’t be that bad. LOL Famous last words…

ReportManager | MQLsoft - [mql, programming, programmer, service, coding, mql4, ea, forex, trading, automated, metatrader, indicator, expert advisor, ea, strategy, ea programming, robot, custom indicators, algorithmic, professional, free, download]
this is free and it lets you combine backtests. But it has its limitations.

you could backtest each pair and find your largest DD and divide the lot sizes by the number of pairs you are running.

What I usually do with forward tests is put the ea on every pair, just to see what happens. Use a small lot size 0.01 for eg. this will give you a good idea of drawdown on each pair. Run it for about 6 months if it survives :slight_smile: . Use myfxbook, etc to isolate each pair. See which ones are good, which are not.

Yes I could, but that wouldn’t show me a worst case scenario, because it wouldn’t attenuate for the timing of those drawdowns.

However, that link you posted is a godsend. It just saved me from having to muddle through C# :smiley:

It will suffice perfectly. I’m not asking anything out of it’s basic parameters. I’ll do all the odd stuff in MT4. I just wanted a closer measure to a true equity curve, be it up or down, against floating p/l situations.

Thanks to all of you!!!

D-Pip… not so much :stuck_out_tongue:

With the backtests, just assume the worst drawdown all happens at the same time. In reality it probably will.

thats a nice simple program I just tested it out. Thanks for the link

Kinda funny how much keyword spam they have in their title. Google looks down on that.

goldylox, brilliant post… presents a completely different and intuitive approach to tackling the problem, I’m grateful :5:

That is actually a fairly limiting assumption, though understandable considering what is being offered.

This leads to a whole other area of possible system performance gains. Rather than optimizing the underlying system or systems, the focus turns to optimizing the combination of equity curves. The process can lead to an overall reduction in variance (drawdown) if done correctly. Markowitz put forward the idea in the 1950s that overall portfolio returns can be increased and drawdown reduced by the combination of uncorrelated equity curves. I have been experimenting with this quite a lot lately and can confirm that portfolio optimization through diversification is one of the few truly free lunches in trading. By free lunch I mean reducing drawdown while at the same time increasing or holding steady returns of the composite portfolio.

If what I’ve said makes any sense at all to the reader of this post, then the link below may change your view of trading systems forever or at least open up your mind to possibilities you never knew existed.

Trader’s Roundtable :: View topic - Blending noncorrelated (or anti-correlated) equity curves

FXEZ, thank you very very much for sharing that resource - I find that ‘sluggo’ is gifted at expressing his ideas, evidenced by my being able to understand everything he presented - you’re a gentleman… but damn, I now have new homework for the next few weeks :frowning:

Cheers re. bringing TB to my attention also. And while I’m here your work in the stat arbs thread hasn’t gone unnoticed, I’ll be finding time to digest the gems there in due course. Keep up the good work!

Does Jforex allow you to test multi currency strategies? That would be like the 5th dimention :slight_smile:

I’m afraid it does - welcome to the 5th Dimension :slight_smile:

Just incase you meant to say multiple multi currency strategies you can do that to as touched upon in this 2011 thread:

http://www.dukascopy.eu/swiss/english/forex/jforex/forum/viewtopic.php?f=65&t=35436&view=unread

Dukascopy continues to evolve the platform and remains very receptive and responsive to feature requests. It’s still very far from perfect but I like the flexibility of using Java.

Java… OMG…

I need to go back to school! My first copy/paste java programs are bringing up lots of errors. You must need new libraries or something… ahhhhh

Lately I have been testing/developing strategies (with mt4) using yes, [U]multiple multi currencies[/U] and the results are very promising. It is like the world use to be flat, then it was round, now it is Swiss Cheese. Being able to backtest these systems would be an advantage.

In the JForex Strategy editor under “Environments” there is an option to select MT4. Haven’t figured it out yet, but it looks like MQL4 is an option to use as a language there…

Somebody smarter than me may need to figure it out though :stuck_out_tongue:

Take a look at MultiCharts, they have a 30 day trial.

They also have various built in data feeds. They’ll have everything you’ll need. You’ll need to use Portfolio backtesting and optimisation features. Then with those results, you can proceed with Monte Carlo simulation and see how robust your system is.

The only thing is you’ll need to code your system with EasyLanguage or PowerLanguage. It’s really not that hard, and in my opinion, easier than MQL4.

If you need help, just let me know.

Clark