MetaTrader 5 Strategy Tester: bugs, bugs, suggestions for improvement - page 48

 

In order to get the grail in pips mode, close losing positions with one marker for the entire position volume, and profitable ones with 0.01 lots.

Example.

#include <MT4Orders.mqh>

#define  Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK)

const bool Init = EventSetTimer(100);

void OnTimer()
{
  while (OrdersTotal())
    if (OrderSelect(0, SELECT_BY_POS))
      OrderClose(OrderTicket(), (OrderProfit() > 0) ? 0.01 : OrderLots(), OrderClosePrice(), 0);
      
  OrderSend(_Symbol, OP_BUY, 1, Ask, 0, 0, 0);
}


Result

 

Forum on trading, automated trading systems and strategy testing

Libraries: SingleTesterCache

fxsaber, 2020.01.12 23:20

The current version of tst-format does not contain the following data

  • Time in milliseconds.
  • PositionID.
  • MagicNumber.
This imposes restrictions in usage scenarios.
 

Forum on trading, automated trading systems and strategy testing

Libraries: SingleTesterCache

fxsaber, 2020.01.13 00:01

Replay multiple bugs. We launch the Expert Advisor in the Strategy Tester on a hedge account.

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

#define  Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK)

#define  PAUSE 100000

void OnTick()
{
  static bool FirstRun = true;
  
  if (FirstRun)
  {
    OrderSend(_Symbol, OP_BUY, 1, Ask, 0, 0, 0);
    Sleep(PAUSE);
    
    OrderSend(_Symbol, OP_BUY, 2, Ask, 0, 0, 0);
    Sleep(PAUSE);

    if (OrderSelect(0, SELECT_BY_POS))
      OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0);
    Sleep(PAUSE * 2);
    
    if (OrderSelect(0, SELECT_BY_POS))
      OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0);
    Sleep(PAUSE * 2);

    TesterWithdrawal(100);    
    
    FirstRun = false;
  }
}

void OnDeinit( const int )
{
  const int Total = OrdersHistoryTotal();
  
  for (int i = 0; i < Total; i++)
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
    {
      OrderPrint();
      
      Print(OrderTicketID()); // MT5-PositionID
    }
}


We get the following

2020.01.08 23:59:58   #1 2020.01.01 00:00:00 balance 0.00 0.00000 0.00000 0.00000 2020.01.01 00:00:00 0.00000 0.00 0.00 100000.00 0
2020.01.08 23:59:58   0
2020.01.08 23:59:58   #4 2020.01.02 06:00:00 buy 1.00 EURUSD 1.12137 0.00000 0.00000 2020.01.02 06:03:20 1.12132 -3.56 0.00 -4.46 0
2020.01.08 23:59:58   2
2020.01.08 23:59:58   #5 2020.01.02 06:01:40 buy 2.00 EURUSD 1.12137 0.00000 0.00000 2020.01.02 06:06:40 1.12129 -7.14 0.00 -14.27 0
2020.01.08 23:59:58   3
2020.01.08 23:59:58   #6 2020.01.02 06:10:00 balance 0.00 0.00000 0.00000 0.00000 2020.01.02 06:10:00 0.00000 0.00 0.00 -100.00 withdrawal 0
2020.01.08 23:59:58   0


Then we read the corresponding tst file using the script.

#include <fxsaber\SingleTesterCache\SingleTesterCache.mqh> // https://www.mql5.com/ru/code/27611
#include <fxsaber\MultiTester\MTTester.mqh> // https://www.mql5.com/ru/code/26132

void OnStart()
{  
  uchar Bytes2[];
  
  if (MTTESTER::GetLastTstCache(Bytes2) != -1) // Если получилось прочитать последнюю кеш-запись одиночного прогона
  {
    const SINGLETESTERCACHE SingleTesterCache(Bytes2); // Загоняем ее в соответствующий объект.

    for (int i = 0; i < ArraySize(SingleTesterCache.Positions); i++)
      Print(SingleTesterCache.Positions[i].ToString());
  }
}


It will print the data on positions

id = 0
mfe = 0.0
mae = -8.029999999999999
profit = -4.46
lifetime = 00:03:20

id = 0
mfe = 0.0
mae = -21.4
profit = -14.27
lifetime = 00:05:00

id = 0
mfe = 0.0
mae = 0.0
profit = 0.0
lifetime = 00:00:00


If we compare everything in this post, we will see the following bugs.

  • Zero id, instead of correct id.
  • Commission and swap are not taken into account when calculating profit.
  • Withdrawal-trade is erroneously included in the number of closed trade positions.

 

The debugger is not entirely functional. What is missing compared to the standard debuggers, in descending order of shortcomings.

1. Memory modification. You can view variables, but editing seems not to be possible.

2. Conditional breakpoints. Like stop if variable test=10.

3. Possibility to move execution. In other words, just click on a line and tell it to execute it from there. In other words, click on a line and say, "Now run from here".

4. an attachment to an already running script/advisor/indicator. Or at least the ability to attach when crashing, so it's easy to analyse.

 
traveller00:

The debugger is not entirely functional. What is missing compared to standard debuggers, in descending order of shortcomings.

2. Conditional breakpoints. Like stop if variable test=10.

if (smth) {

    int a;

}
 
Yes, I agree, you can achieve almost anything by reassembly. Except for point 4. 4. But I would still like to see it in the debugger, because it is a standard set of functions for the debugger.
 

Forum on trading, automated trading systems and strategy testing

Libraries: SingleTesterCache

fxsaber, 2020.01.14 10:49

I use tst-files instead of set-files now. You can switch between them very quickly, having not only input parameters but also full backtests.

It's a pity that we cannot combine different TSs in a full-fledged portfolio now due to lack of millisecond data in tst.


I hope the developers will start using the existing fields to the fullest extent

INT64             TradeDeal::time_create;             // время создания записи

INT64             TradeOrder::time_setup;             // время приёма ордера от клиента в систему
INT64             TradeOrder::time_done;              // время снятия завки

by writing there the time value in milliseconds instead of seconds.


Generally, in practice we cannot demonstrate all the coolness of using tst because of some slight drawbacks in tst. This could be corrected.

 


TesterWithdrawal is in the report, but TesterDeposit is missing.

 
How to understand this picture. The optimisation graph shows peak values around 5000. But in the optimisation table the maximum value is 4670. Where are the parameters for the best passes ?
Files:
8c97so2_7-1.jpg  184 kb
 
Grozir:
How to understand this picture. The optimisation graph shows peak values around 5000. And in the optimisation table the maximum value is 4670. Where are the parameters for the best passes ?

Sort the "Result" column.