MT4-Tester VS MT5-Tester

 
I have finally realized an old idea

Forum on trading, automated trading systems and trading strategy testing

Discussion on "Ready-made EAs from MQL5 Wizard work in MetaTrader 4"

fxsaber, 2017.03.09 13:02

I suggest to take Tick Data Suite trial (Compatible: MT4 build 940 - 1052) for comparison.

In MT5 tester select "by real ticks" mode. Save them and feed them to the MT4 tester via TDS.

Then the quotes in both testers will coincide 100%, which will allow comparing them not only in trades, but also in speed.

It would then be possible to compare the conversion/creation of EAs in both directions.

MT4 build 1072, MT5 build 1596 trading server Alpari-MT5.

MT4 tester settings on the screenshot

Currency in both testers is USD. This allows in the same MT5 tester for EURUSD not to pull another tick of conversion symbol.


Now we run the following cross-platform Expert Advisor in both testers

// MQL4&5-code

#property strict

class FILE
{
private:
  const int handle;
  
  static string TickToString( const MqlTick &Tick, const string Delimeter = " " )
  {
    return(::DoubleToString(Tick.ask, _Digits) + Delimeter + ::DoubleToString(Tick.bid, _Digits));
  }
public:  
  FILE( const string FileName ) : handle(::FileOpen(FileName, FILE_WRITE | FILE_TXT | FILE_ANSI))
  {
  }
  
  ~FILE( void )
  {
    if (this.handle != INVALID_HANDLE)
      ::FileClose(handle);       
  }
  
  bool Write( const MqlTick &Tick ) const
  {
    return((this.handle != INVALID_HANDLE) && ::FileWriteString(this.handle, FILE::TickToString(Tick) + "\n"));
  }
};

const FILE File(::MQLInfoString(MQL_PROGRAM_NAME) + ".txt");

void OnTick()
{
  MqlTick Tick;
  
  if (SymbolInfoTick(_Symbol, Tick))
    File.Write(Tick);
}


MT4-tester log

2017.05.07 23:25:36.155 EURUSD,M1: 1865415 tick events (7292 bars, 1865515 bar states) processed in 0:00:02.528 (total time 0:00:03.292)


MT5-tester log

2017.05.07 23:26:01.016 Core 1  EURUSD,M1: 1865415 ticks, 7192 bars generated. Test passed in 0:00:01.918 (including ticks preprocessing 0:00:00.203).

We confirm that the files received from each tester are identical - the ticks of the testers coincide.


At this point the preparation of both testers for the new service is ready.

 

Expert Advisor

// MQL4&5-code

#include <MT4Orders.mqh> // https://www.mql5.com/ru/code/16006

#ifdef __MQL5__
  #define Bid (SymbolInfoDouble(_Symbol, SYMBOL_BID))
  #define Ask (SymbolInfoDouble(_Symbol, SYMBOL_ASK))
#endif // __MQL5__

// Idea - https://www.mql5.com/ru/code/7464
#property strict

input int Shift = 3; 
input int Limit = 18;
input double Lots = 0.1;

int PriceToInteger( const double Price )
{
  return((int)(Price / _Point + 0.1));
}

void OnTick()
{
  static int PrevBid = PriceToInteger(Bid);
  static int PrevAsk = PriceToInteger(Ask);    

  const int IntBid = PriceToInteger(Bid);
  const int IntAsk = PriceToInteger(Ask);
  
  const bool TradeTime = (TimeCurrent() % (24 * 60 * 60) < D'1970.01.01 23:50'); // exclude swaps
  
  if (TradeTime && (IntAsk - IntBid < Limit))
  {
    if ((IntBid - PrevBid >= Shift)) 
      OrderSend(_Symbol, OP_SELL, Lots, Bid, 0, 0, 0);
    
    if (PrevAsk - IntAsk >= Shift) 
      OrderSend(_Symbol, OP_BUY, Lots, Ask, 0, 0, 0);
  }

  PrevBid = IntBid;
  PrevAsk = IntAsk;
  
  for (int i = OrdersTotal() - 1; i >= 0; i--) 
    if (OrderSelect(i, SELECT_BY_POS) && ((!TradeTime) || (OrderProfit() > 0) ||
        ((OrderType() == OP_BUY)  && (PriceToInteger(OrderOpenPrice()) - IntBid >= Limit)) ||
        ((OrderType() == OP_SELL) && (IntAsk - PriceToInteger(OrderOpenPrice()) >= Limit)))) 
      OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0); 
}


The results


MT4 report

Strategy Tester Report
Lucky
MetaQuotes-Demo (Build 1072)

SymbolEURUSD (Euro vs US Dollar)
Period1 Minute (M1) 2017.04.10 00:00 - 2017.04.14 20:58 (2017.04.10 - 2017.04.16)
ModelAll ticks (most accurate method based on all smallest available timeframes)
ParametersShift=3; Limit=18; Lots=0.1;
Bars in history7292Modelled ticks1865515Modeling quality99.00%
Chart mismatch errors0
Initial deposit100000.00SpreadVariable
Net profit-10863.90Total profit2528.70Total loss-13392.60
Profitability0.19Expected payoff-0.49
Absolute drawdown10864.70Maximum drawdown10864.70 (10.86%)Relative drawdown10.86% (10864.70)
Total trades21954Short positions (% win)12016 (68.60%)Long positions (% win)9938 (67.03%)
Profitable trades (% of all)14904 (67.89%)Loss trades (% of all)7050 (32.11%)
Largestprofitable trade3.00losing transaction-4.40
Averageprofitable deal0.17losing trade-1.90
Maximum numbercontinuous wins (profit)155 (46.60)Continuous losses (loss)115 (-210.10)
Max.continuous profits (number of wins)46.60 (155)continuous loss (number of losses)-210.10 (115)
Averagecontinuous winnings5continuous loss2


MT5 Report

Strategy Tester report
Alpari-MT5 (Build 1596)
Settings
Expert Advisor:Lucky
Symbol:EURUSD
Period:M1 (2017.04.10 - 2017.04.16)
Parameters:Shift=3
Limit=18
Lots=0.1
Broker:Alpari International Limited
Currency:USD
Initial deposit:100 000.00
Leverage:1:100
Backtest
Story quality:n/a
Bars:7192Tiki:1865415Characters:1
Net profit:-10 863.90Absolute drawdown on balance sheet:10 863.90Absolute drawdown on funds:10 864.70
Total profit:2 528.70Maximum drawdown on balance:10 863.90 (10.86%)Maximum drawdown of funds:10 864.70 (10.86%)
Total loss:-13 392.60Relative drawdown on balance sheet:10.86% (10 863.90)Relative drawdown on funds:10.86% (10 864.70)
Profitability:0.19Expected payoff:-0.49Margin level:863.58%
Recovery Factor:-1.00Sharpe Ratio:-0.50Z-score:-52.22 (99.74%)
AHPR:1.0000 (-0.00%)LR Correlation:-1.00OnTester Result:0
GHPR:1.0000 (-0.00%)LR Standard Error:149.82
Total trades:21954Short trades (% of winners):12016 (68.60%)Long trades (% wins):9938 (67.03%)
Total trades:43908Profitable trades (% of all trades):14904 (67.89%)Loss trades (% of all trades)7050 (32.11%)
Largest profitable trade3.00Largest losing trade-4.40
Average profitable trade:0.17Average losing trade:-1.90
Maximum number of consecutive wins (profit):155 (46.60)Maximum number of continuous losses (loss):115 (-210.10)
Max. continuous profits (number of wins):46.60 (155)Max. continuous loss (number of losses):-210.10 (115)
Average continuous winnings:5Average Continuous Losses:2


The results are a match!


Performance

MT4-log
2017.05.08 01:45:42.765 EURUSD,M1: 1865415 tick events (7292 bars, 1865515 bar states) processed in 0:00:03.682 (total time 0:00:04.400)


MT5-log

2017.05.08 02:04:53.278 Core 1  EURUSD,M1: 1865415 ticks, 7192 bars generated. Test passed in 0:00:12.309 (including ticks preprocessing 0:00:00.203).


MT4-tester has managed 3 times faster than MT5-tester. If there is any doubt that the MT5-logging is caused by using a third party library, those who wish may rewrite the simple MT4-logic of this Expert Advisor in MQL5 in their own way and check the hypothesis.


HZ the MT5 tester was working much slower, until I cleaned all Bases folders by hand. The results are given with this in mind.

 

On Alpari-MT5-Demo server in the new build (to be released in a week) with quick access to deal history I have succeeded:

EURUSD,M1: 1865417 ticks, 7192 bars generated. Test passed in 0:00:05.578.

MT5 has a system overhead for transferring data and the task itself to an external agent process, which on small (seconds) tasks introduces a big error in comparison.

And the complexity and quality of the tester in MT5 is much higher: synchronous modeling of many instruments with millisecond accuracy, real slips/delays during scrolling of world changes and a lot of more minor functions. It's not like there's a for loop.


Slower by orders of magnitude - aren't you confused with initialization/synchronization and uploading of all data? Everything is written in logs. The files on the disk should not be touched in any case.

I recommend to put %userdata%\MetaQuotes directory (like C:\Users\%username%\AppData\Roaming\MetaQuotes) into antivirus pass. This is where the data lies and adding the antivirus to the pass dramatically improves the speed of access to the terminal and tester data.

Otherwise, they get so excited when they see metatester[64].exe running, opening network port and a lot of large data files, written by terminal and tester. Some traders' tester even manages to fall off, because antivirus does not have time to check the metatester[64].exe file even in a few seconds and the terminal is unable to access it.

 
Renat Fatkhullin:

the complexity and quality of the tester in MT5 is an order of magnitude higher: synchronous modelling of multiple instruments with millisecond accuracy, honest slips/delays while scrolling through world changes and a bunch of smaller features.

The MT4+TDS bundle has that too. Plus some more features that MT5 lacks... But of course there's no multicurrency.

Slower by orders of magnitude.

At first I thought that TDS deliberately slows down MT5, so I cleaned its memory. I also cleaned Bases-folders (I was running out of disk space). After that MT5 was two orders of magnitude faster for a single run (reboots didn't help before). The hypothesis about TDS-blocks could not be confirmed, however I tried. I have not had any anti-viruses on my computer.

Alpari-MT5 server is real.


ZZY ran MT4-optimizer on full execution - 14 minutes. MT5 (only one agent left) - looks like it will be many hours. Will post the total in the morning/afternoon.

 

Where did the slips come from?

You have something completely different in mind. Play with the Delay field in MT5 tester and you will see that it is something else entirely. Even the usual Sleep(2500) in MQL5 code, when executed in the tester, will give a delay in the code when the whole world keeps simulating. The execution delay field effectively shows how trades will execute if you put your 100ms ping to the server there.

There can't be an order of magnitude lag. And why would there be any add-ons for MT5 when it works fine on its own.

About overshooting - there are no settings and no limits.
 

About the lack of antivirus - for a long time now, all versions since 7 have had an in-house and inconspicuous Windows Defender, which does a good job of scanning all files.

Sometimes it generates noticeable lags in file operations even on SSD disks.

 

Overkill (100,000 USD at the start)


Slips in MT4 (the milliseconds in tick history works as it should) and other goodies


 
Renat Fatkhullin:

About the lack of antivirus - for a long time now, all versions from 7 have had an in-house and inconspicuous Windows Defender, which scans all files.

Disabled. Already have all data to see strong MT5 slowdowns on optimization. I will post comparative optimization results when MT5 is finished.
 
I do not understand the idea of duplicates

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

fxsaber, 2017.05.07 21:55

Alpari-MT5 trading server

Why are there duplicate ticks (bid and ask are equal) in FOREX tick history?

The tester is racing EAs on duplicates and there are half of them. Is it necessary to obtain the appropriate performance drop by half?

 

You still don't understand the slips I'm talking about. It doesn't work in MT4 as a matter of principle.

Not in ticks, but in the process of mcl5 programme, when it stops and the ticks keep going and the world is spinning. Write Sleep(3000) and the program will wait for 3 seconds and during this time the ticks will be ticking, the market will be simulating.

If you set the Execution Delay field to 200ms in the tester, a net latency of 200 when executing trades will be simulated, which will give either market slippage or requotes.

This is a whole other powerful level of market process modelling, and within a multi-currency system. And more importantly, in a remote alienated process. For example, a 10,000km agent suddenly receives a dynamic request for access to missing symbols from the code when performing a task and is able to request this data from the master, embed it in the market world and continue to spin it.

 
Renat Fatkhullin:

You still don't understand the slips I'm talking about. It doesn't work in MT4 as a matter of principle.

Not in ticks, but in the process of mcl5 programme, when it stops and the ticks keep going and the world is spinning. Write Sleep(3000) and the program will wait for 3 seconds and in that time the ticks will be ticking, the market will be simulating.

This does not work now in MT4.

If you set the Execution Delay field to 200ms in the tester, it will simulate a net latency of 200 when executing trades, which will give either market slippage or requotes.

This works now in MT4.

This is a whole other powerful level of market process modelling, and within a multi-currency system. And more importantly, in a remote alienated process. For example, a 10,000km agent suddenly receives a dynamic request for access to missing symbols from the code when performing a task and is able to request this data from the master, embed it in the market world and continue to spin it.

I have no aim to denigrate the MT5. I'm only making a reproducible comparison. Of course, the MT5 tester is unreachable by some parameters, but the MT4 tester is able to give the things, which are not present in the MT5, but which are really needed. We have seen that an accurate test on real custom ticks on MT4 is 100% true. Well, and the regulation of all sorts of settings (commission, indents, rules of activation of pending orders, etc.) of the tester is there. In general, there are things that are not implemented in MT5 yet.
Reason: