Analysis of test results and optimisation in the MetaTrader 5 strategy tester - page 2

 
Anatoli Kazharski:

The long parameter (lparam) is checked. The identifier of the tick event is contained in it.

The identifier of the user event (int id) is equal to zero.

It can be written in this way to make it clearer:

I understand that everything should be rewritten to make it work correctly. I'll show you now.

 
fxsaber:

I realised that everything needs to be rewritten to make it work correctly. I'm about to do it.

And I can't, because this shit is happening.

2018.01.28 12:37:23.692 Tester  EURUSD: preliminary downloading of history ticks started, it may take quite a long time
2018.01.28 12:37:24.692 Tester  EURUSD: preliminary downloading of history ticks completed, 89 bytes in 0:00.998 (0.09 Kb/sec)
2018.01.28 12:37:24.692 Tester  EURUSD: ticks data begins from 2017.09.01 00:00
2018.01.28 12:37:24.692 Core 1  agent process started
2018.01.28 12:37:33.425 Core 1  connecting to 127.0.0.1:3000
2018.01.28 12:37:50.450 Core 1  tester agent authorization error
2018.01.28 12:37:50.456 Core 1  connection closed
and I can't get the tester to run.
 

Indicator

#property indicator_chart_window
#property indicator_plots 0

input long Chart = 0; // идентификатор графика-получателя события
input int Index = 0;

int OnCalculate( const int rates_total, const int prev_calculated, const int, const double &[] )
{
  if (prev_calculated)
    EventChartCustom(Chart, 0, Index, 0, NULL);
  
  return(rates_total);
}


Expert Advisor

#include <TesterBenchmark.mqh> // https://www.mql5.com/ru/code/18804

input int AmountSymbols = 1;

const string Symbols[] = {"EURUSD", "GBPUSD", "AUDUSD", "USDJPY", "USDCAD"};

double Sum2 = 0;

double GetBid( const string &Symb )
{
  static MqlTick Tick;

  return(SymbolInfoTick(Symb, Tick)? Tick.bid : 0);
}

void OnInit()
{
  for (int i = 0; i < AmountSymbols; i++)
    iCustom(Symbols[i], PERIOD_W1, "Spy.ex5", ChartID(), i); // MQL5\Indicators\Spy.ex5
}

void OnDeinit( const int )
{
  Print(Sum2);
}

void OnTick()
{
}

void OnChartEvent( const int id, const long &lparam, const double&, const string& )
{
  if (id == CHARTEVENT_CUSTOM)
    Sum2 += GetBid(Symbols[(int)lparam]);
}

EURUSD M1 MetaQuotes-Demo, Hedge, USD, no lag, Core1-agent only, real ticks 01.09.2017 - 28.01.2018.


One symbol

i = 0 Pass = 0 OnTester = 7.053 s.: Count = 9986677, 1415947.4 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755
i = 1 Pass = 1 OnTester = 6.930 s.: Count = 9986677, 1441078.9 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755


Two symbols

i = 0 Pass = 0 OnTester = 25.747 s.: Count = 9986677, 387877.3 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755
i = 1 Pass = 1 OnTester = 26.118 s.: Count = 9986677, 382367.6 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755


Three symbols

i = 0 Pass = 0 OnTester = 47.448 s.: Count = 9986677, 210476.2 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755
i = 1 Pass = 1 OnTester = 46.994 s.: Count = 9986677, 212509.6 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755


  1. In single symbol mode, the "spy" is 2.5 times slower than pure OnTick. I.e. the empty indicator (built on PERIOD_W1 so that bar history is minimal) has a huge overhead in the Tester!
  2. Two symbols are 3.5 times slower than one.
  3. But three symbols are only 1.8 times slower than two symbols. I.e. the transition from two to three is due to scalability. as opposed to item 2.
 

Anatoly, I suggest moving the topic to Forex Experts, Trading Robots and Expert Advisors and fixing it at the top there.

This way it will be always in view. There are already a lot of posted topics here

 
Rashid Umarov:

Anatoly, I suggest moving the topic to Forex Experts, Trading Robots and Expert Advisors and fixing it at the top there.

This way it will be always in view. There are already a lot of posted topics here

I do not mind if the topic might be useful.
 
fxsaber:

...

  1. In single symbol mode Spy is 2.5 times slower than pure OnTick. I.e. empty indicator (built on PERIOD_W1, so that bar history is minimal) has a huge overhead in the Tester!
  2. Two symbols are 3.5 times slower than one.
  3. But three symbols are only 1.8 times slower than two symbols. That is, the transition from two to three is due to scalability. unlike in point 2.

Your result is 6, 25, 46. Why not 6, 12 and 18?

You have to look at the deceleration relative to a single character. Then three characters are almost 8 times slower than one, not 3 as expected.

The question is exactly this. Why is there such a result with scalability? And if the result cannot be improved, an option for a new test mode was suggested. This would solve the problem of long tests when using multiple characters.

Forum on trading, automated trading systems and trading strategy testing

Analysis of Tests and Optimization in MetaTrader 5 Strategy Tester

Anatoli Kazharski, 2018.01.27 20:15

Question:

Is it possible to create such a multisymbol Expert Advisor scheme in MQL, so that the duration of tests does not increase repeatedly when adding symbols to the test?

//---

If this is not possible, then one of the options for the developers of the terminal is to add one more mode, when you can run the test symbol by symbol, rather than all symbols at once. This would produce the expected test time in the end. The point is that multisymbol EAs are very often used simply for those cases where:

  1. More data is needed for tests.
  2. To test the trading algorithm on a larger variety of price behaviour, conditions (spread, stop/limit levels), etc., with the same parameters.

It is for such cases we need a new mode that would allow us to significantly reduce the duration of tests and optimize parameters. And already for the final test to test all symbols simultaneously.


 
Anatoli Kazharski:

You have a result of 6, 25, 46. Why not 6, 12 and 18?

The deceleration has to be looked at in relation to one symbol.

Two characters with spikes is a much different tester mode than a single character. Therefore it is logical to look at the scalability relative to two.

Moreover, the indicator overhead is so wild that working through the spies is a crutch. Waiting for Services, where scalability should be almost perfect, relative to just one symbol. As is the case with the timer. Only there there will be no tick skips.

 
Significantly accelerated
#include <TesterBenchmark.mqh> // https://www.mql5.com/ru/code/18804

input int AmountSymbols = 1;

const string Symbols[] = {"EURUSD", "GBPUSD", "AUDUSD", "USDJPY", "USDCAD"};

double Sum2 = 0;

double GetBid( const string &Symb )
{
  static MqlTick Tick;

  return(SymbolInfoTick(Symb, Tick)? Tick.bid : 0);
}

void OnInit()
{
  for (int i = 0; i < AmountSymbols; i++)
    if (Symbols[i] != _Symbol)
      iCustom(Symbols[i], PERIOD_W1, "Spy.ex5", ChartID(), i); // MQL5\Indicators\Spy.ex5
}

void OnDeinit( const int )
{
  Print(Sum2);
}

void OnTick()
{
  OnTick(_Symbol); 
}

void OnTick( const string &Symb )
{
  Sum2 += GetBid(Symb);
}

void OnChartEvent( const int id, const long &lparam, const double&, const string& )
{
  if (id == CHARTEVENT_CUSTOM)
    OnTick(Symbols[(int)lparam]);
}


One symbol

i = 0 Pass = 0 OnTester = 2.697 s.: Count = 9986677, 3702883.6 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755
i = 1 Pass = 1 OnTester = 2.657 s.: Count = 9986677, 3758628.9 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755


Two digits

i = 0 Pass = 0 OnTester = 17.632 s.: Count = 9986677, 566395.0 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755
i = 1 Pass = 1 OnTester = 17.539 s.: Count = 9986677, 569398.3 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755


Three symbols

i = 0 Pass = 0 OnTester = 35.639 s.: Count = 9986677, 280217.7 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755
i = 1 Pass = 1 OnTester = 35.462 s.: Count = 9986677, 281616.3 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755


Four symbols

i = 0 Pass = 0 OnTester = 68.459 s.: Count = 9986677, 145878.2 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755
i = 1 Pass = 1 OnTester = 69.429 s.: Count = 9986677, 143840.1 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1755
 
fxsaber:

Two characters with spies is a very different mode of operation for a tester than a single character. Therefore it is logical to look at scalability relative to two.

Moreover, the indicator overhead is so wild that working through the spies is a crutch. Waiting for Services, where scalability should be almost perfect, relative to just one symbol. As is the case with the timer. Only there there will be no tick skips.

fxsaber:
Significantly accelerated

One symbol

Two symbols

Three characters

Four characters

If we look at the results relative to two symbols, then we divide the result of two symbols by two: 17 / 2 = 8.5

Then, when adding symbols, we multiply this value by the number of symbols to get the expected test time.

  • three characters: 8.5 * 3 = 25, and the actual time is35.462 s.
  • four characters: 8.5 * 4 = 34, while the actual time is68.459 s.

But this is in any case the best result so far. An interesting variant is to use the current symbol in OnTick, while the rest in custom events.

You may use it while there are no services.

This is a forum for trading, automated trading systems and strategy testing.

Init() and DeInit() execution sequence

Slava, 2017.04.14 10:18

The services, among other things, will have trading functions and the ability to manage objects. And charts.

Market data provider is only one possibility.

Forum on trading, automated trading systems and trading strategy testing

Init() and DeInit() execution sequence

Slava, 2017.04.14 10:21

The services will have OnTick(string symbol). But the ticks from a particular symbol will need to be subscribed to

Forum on trading, automated trading systems and trading strategies testing

Init() and DeInit() execution sequence

fxsaber, 2017.04.14 10:46

It turns out that Services will have almost all On functions: OnInit, OnDeinit, OnTick(string),OnTimer,OnTrade,OnTradeTransaction, OnTester, OnTesterInit, OnTesterPass, OnTesterDeinit, OnBookEvent, OnChartEvent(long ChartID, ...), OnCalculate, ...

And if you don't need indicator buffers and don't want to deal with indicators/advisors crutches, write in a new type of program - Services - that doesn't have any limitations (stretching from the previous versions of MT).

Forum on trading, automated trading systems and trading strategies testing

Sequence of Init() and DeInit() execution

Slava, 2017.04.14 10:56

Exactly.

There will be no OnCalculate.

There is no solution with OnChartEvent yet.

 
Reason: