Download MetaTrader 5

How to get backtesting faster ?

To add comments, please log in or register
mmfxmmfx
86
mmfxmmfx  

Need help to run backtesting using MT4 faster, What do I need for doing it ?

honest_knave
Moderator
2326
honest_knave  

Optimize your code.

Alain Verleyen
Moderator
33358
Alain Verleyen  
honest_knave:

Optimize your code.

And optimize your computer
Pablo Medina Betancor
837
Pablo Medina Betancor  
I must add: use open prices
Stanislav Korotky
21610
Stanislav Korotky  
mmfxmmfx:

Need help to run backtesting using MT4 faster, What do I need for doing it ?

In brief:

  • If your trading strategy allows for this - consider using bar-wise trading mode instead of tick-wise: if EA is designed and properly implemented for trading by bar, it's results in "Open prices only" mode can be acceptable; in any case you can always compare reasults from different price simulation models and decide for yourself if this approach is suitable;
  • If you use indicators and have their source codes - move their core algorithm into the EA itself: invocation via iCustom/CopyXXX implies noticable overheads;
  • Run profiler for your EA and pinpoint bottlenecks: as a result you can try to optimize problematic places (as others suggested), change EA settings, cache some internal data to prevent recalculation etc.
mmfxmmfx
86
mmfxmmfx  

I need to know if the computer specification is the main issue or the EA programining that couse to the backtest to be slow ...

Can you advise about PC specification that is MUST for backtesting. 

What is the normal time for 4 years baktesting ?
honest_knave
Moderator
2326
honest_knave  
mmfxmmfx:

I need to know if the computer specification is the main issue or the EA programining that couse to the backtest to be slow ...

Can you advise about PC specification that is MUST for backtesting. 

What is the normal time for 4 years baktesting ?

Nobody can answer these questions without seeing the code and your computer specs.

Generally speaking, it is inefficient code that really slows things down.

Strategy tester in MT4 is only single core anyway.

You might want to consider porting your code to MQL5 and using the cloud network - https://www.mql5.com/en/articles/341

Speed Up Calculations with the MQL5 Cloud Network
Speed Up Calculations with the MQL5 Cloud Network
  • 2012.02.07
  • MetaQuotes Software Corp.
  • www.mql5.com
How many cores do you have on your home computer? How many computers can you use to optimize a trading strategy? We show here how to use the MQL5 Cloud Network to accelerate calculations by receiving the computing power across the globe with the click of a mouse. The phrase "Time is money" becomes even more topical with each passing year, and we cannot afford to wait for important computations for tens of hours or even days.
Stanislav Korotky
21610
Stanislav Korotky  
mmfxmmfx:

I need to know if the computer specification is the main issue or the EA programining that couse to the backtest to be slow ...

Can you advise about PC specification that is MUST for backtesting. 

What is the normal time for 4 years baktesting ?

You can always implement inefficient enough code to slow down any imaginable super computer ;-). Multicore with 4Gb is normally ok.

Backtest time depends from your algorithm - for example, one may train a large NN on route, then it can take a day. We should not speculate here on what your EA algorithm does. Please provide more details if you want help.

Please, bear in mind that MT5 is more resource consuming than MT4, so porting EA to MT5 (as others suggested) can make things even worse.

Just profile your code.

honest_knave
Moderator
2326
honest_knave  
Stanislav Korotky:

You can always implement inefficient enough code to slow down any imaginable super computer ;-). Multicore with 4Gb is normally ok.

Backtest time depends from your algorithm - for example, one may train a large NN on route, then it can take a day. We should not speculate here on what your EA algorithm does. Please provide more details if you want help.

Please, bear in mind that MT5 is more resource consuming than MT4, so porting EA to MT5 (as others suggested) can make things even worse.

Just profile your code.


To clarify: the suggestion of porting to MT5 was to have access to the cloud network, which Metaquotes claim:

Use the MQL5 Cloud Network!

The phrase "Time is money" becomes even more topical with each passing year, and we cannot afford to wait for important computations for tens of hours or even days. At the time of this writing, the MQL5 Cloud Network provides increase of calculations in a hundred times. With its further increase, the gain in time can grow to a thousand times or more. In addition, the network of distributed computing allows you to solve not only strategy optimization tasks.

You can develop a program in MQL5 that implements massive mathematical calculations and requires a lot of CPU resources. The MQL5 language, in which programs for the MetaTrader 5 terminal are written, is very close to C++ and allows you to easily translate algorithms written in other high level languages. 

An important feature of the MetaTrader 5 terminal tester is that hard mathematical tasks aimed at finding solutions with large sets of input variables are easily parallelized among testing agents. And you do not need to write any special code for that - just connect to the MQL5 Cloud Network of distributed computing!


Before you go spending a fortune on a new CPU, you might want to assess how much benefit you'll see from a single-core limited process (MT4 strategy tester).

Stanislav Korotky
21610
Stanislav Korotky  
honest_knave:

To clarify: the suggestion of porting to MT5 was to have access to the cloud network, which Metaquotes claim:

That's correct. But with inefficient code this is just an exchange of time for money. So, naturally, next question would be how to make backtesting cheaper ;-).
whroeder1
15930
whroeder1  
mmfxmmfx:run backtesting using MT4 faster

Don't do per tick what can be delayed.

void OnTick(){
   static datetime time0=0; datetime timep=time0; time0=Time[0];
   bool isNewBar = timep != time0;

   #define PRICE_MAX EMPTY_VALUE
   #define PRICE_MIN 0
   static double buyLevel=PRICE_MAX, sellLevel=PRICE_MIN;
   if(isNewBar){
      buyLevel=PRICE_MAX; sellLevel=PRICE_MIN;
      // calls to indicators etc. goes here.
      if(isBuyCondition)   buyLevel= ...;
      if(isSellCondition) sellLevel= ...;
   }
   if(Bid >= buyLevel){
      // reevaluate buy conditions/SL/TP if necessary
      // calls to indicators etc. goes here.
      // compute lots
      // open buy
   }
   else if(Bid <= sellLevel){
      ... 
   }
   // else nothing to do yet, except maybe update status.
}
To add comments, please log in or register