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

 
fxsaber:

Instructions for playback on any character are available. Any questions - just run it.

No, I'd rather you, by the time I figure out your codes, I'll forget why I started it ))

Can you test on a stock futures eg Si ? Do you want a stock account for the test?

 
Sergey Chalyshev:

No, I prefer you, by the time I figure out your codes I'll forget why I started it))

Can you test it on an exchange futures, for example Si ? Do you want an exchange account for the test?

The exchange has a problem with low liquidity and order queues. Therefore the tester on the Moscow Exchange is not correct. There is practically no such a phenomenon with small lots on Forex. Although it does occur sometimes.

 
Sergey Chalyshev:

Shall I give you a stock account for a test?

Yes. But I should point out right away that any execution at last-price in the Tester is an error.

 
Check code for correctness of the Tester.
#include <MT4Orders.mqh> // https://www.mql5.com/ru/code/16006

#define  Bid SymbolInfoDouble(_Symbol, SYMBOL_BID)
#define  Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK)

void CloseAll()
{
  for (int i = OrdersTotal() - 1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS))
    {
      if (OrderType() <= OP_SELL)
        OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0);
      else
        OrderDelete(OrderTicket());
    }    
}

bool Check1()
{
  bool Res = true;
  
  Res &= OrderSend(_Symbol, OP_BUY, 1, Ask, 0, Bid, 0) && !OrdersTotal();
  CloseAll();

  Res &= OrderSend(_Symbol, OP_BUY, 1, Ask, 0, 0, Bid) && !OrdersTotal();
  CloseAll();

  Res &= OrderSend(_Symbol, OP_SELL, 1, Bid, 0, Ask, 0) && !OrdersTotal();
  CloseAll();

  Res &= OrderSend(_Symbol, OP_SELL, 1, Bid, 0, 0, Ask) && !OrdersTotal();
  CloseAll();
  
  return(Res);
}

bool Check2()
{
  bool Res = true;
  
  Res &= OrderModify(OrderSend(_Symbol, OP_BUY, 1, Ask, 0, 0, 0), Ask, Bid, 0, 0) && !OrdersTotal();
  CloseAll();

  Res &= OrderModify(OrderSend(_Symbol, OP_BUY, 1, Ask, 0, 0, 0), Ask, 0, Bid, 0) && !OrdersTotal();
  CloseAll();

  Res &= OrderModify(OrderSend(_Symbol, OP_SELL, 1, Bid, 0, 0, 0), Bid, Ask, 0, 0) && !OrdersTotal();
  CloseAll();

  Res &= OrderModify(OrderSend(_Symbol, OP_SELL, 1, Bid, 0, 0, 0), Bid, 0, Ask  , 0) && !OrdersTotal();
  CloseAll();
  
  return(Res);
}

bool Check3()
{
  bool Res = true;
  
  Res &= OrderSelect(OrderSend(_Symbol, OP_BUYLIMIT, 1, Ask, 0, 0, 0), SELECT_BY_TICKET) && (OrderType() <= OP_SELL);
  CloseAll();

  Res &= OrderSelect(OrderSend(_Symbol, OP_SELLLIMIT, 1, Bid, 0, 0, 0), SELECT_BY_TICKET) && (OrderType() <= OP_SELL);
  CloseAll();

  Res &= OrderSelect(OrderSend(_Symbol, OP_BUYSTOP, 1, Ask, 0, 0, 0), SELECT_BY_TICKET) && (OrderType() <= OP_SELL);
  CloseAll();

  Res &= OrderSelect(OrderSend(_Symbol, OP_SELLSTOP, 1, Bid, 0, 0, 0), SELECT_BY_TICKET) && (OrderType() <= OP_SELL);
  CloseAll();
  
  return(Res);
}

bool Check4()
{
  bool Res = true;
  
  const double TickSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
  
  Res &= OrderModify(OrderSend(_Symbol, OP_BUYLIMIT, 1, Ask - TickSize, 0, 0, 0), Ask, 0, 0, 0) && (OrdersTotal() == 1) && (OrderSelect(0, SELECT_BY_POS)) && (OrderType() <= OP_SELL);
  CloseAll();  

  Res &= OrderModify(OrderSend(_Symbol, OP_BUYSTOP, 1, Ask + TickSize, 0, 0, 0), Ask, 0, 0, 0) && (OrdersTotal() == 1) && (OrderSelect(0, SELECT_BY_POS)) && (OrderType() <= OP_SELL);
  CloseAll();

  Res &= OrderModify(OrderSend(_Symbol, OP_SELLLIMIT, 1, Bid + TickSize, 0, 0, 0), Bid, 0, 0, 0) && (OrdersTotal() == 1) && (OrderSelect(0, SELECT_BY_POS)) && (OrderType() <= OP_SELL);
  CloseAll();

  Res &= OrderModify(OrderSend(_Symbol, OP_SELLSTOP, 1, Bid - TickSize, 0, 0, 0), Bid, 0, 0, 0) && (OrdersTotal() == 1) && (OrderSelect(0, SELECT_BY_POS)) && (OrderType() <= OP_SELL);
  CloseAll();

  return(Res);
}

bool Check5()
{
  bool Res = true;

  const double TickSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
  
  Res &= OrderModify(OrderSend(_Symbol, OP_BUYLIMIT, 1, Ask - TickSize, 0, 0, 0), Ask, Bid, 0, 0) && !OrdersTotal();
  CloseAll();  

  Res &= OrderModify(OrderSend(_Symbol, OP_BUYSTOP, 1, Ask + TickSize, 0, 0, 0), Ask, Bid, 0, 0) && !OrdersTotal();
  CloseAll();  

  Res &= OrderModify(OrderSend(_Symbol, OP_SELLLIMIT, 1, Bid + TickSize, 0, 0, 0), Bid, Ask, 0, 0) && !OrdersTotal();
  CloseAll();  

  Res &= OrderModify(OrderSend(_Symbol, OP_SELLSTOP, 1, Bid - TickSize, 0, 0, 0), Bid, Ask, 0, 0) && !OrdersTotal();
  CloseAll();  

  return(Res);
}

bool Check6()
{
  bool Res = true;
  
  Res &= OrderSend(_Symbol, OP_BUYLIMIT, 1, Ask, 0, Bid, 0) && !OrdersTotal();
  CloseAll();

  Res &= OrderSend(_Symbol, OP_BUYSTOP, 1, Ask, 0, Bid, 0) && !OrdersTotal();
  CloseAll();

  Res &= OrderSend(_Symbol, OP_SELLLIMIT, 1, Bid, 0, Ask, 0) && !OrdersTotal();
  CloseAll();

  Res &= OrderSend(_Symbol, OP_SELLSTOP, 1, Bid, 0, Ask, 0) && !OrdersTotal();
  CloseAll();
  
  return(Res);
}


#define  TOSTRING(A) #A + " = " + (string)(A) + "\n"

void OnTick()
{
  Print(TOSTRING(Check1()) + TOSTRING(Check2()) + TOSTRING(Check3()) +
        TOSTRING(Check4()) + TOSTRING(Check5()) + TOSTRING(Check6()));

  ExpertRemove();
}


If working correctly, there should be

2019.12.19 00:27:59.263 2019.12.13 00:00:00   Check1() = true
2019.12.19 00:27:59.263 2019.12.13 00:00:00   Check2() = true
2019.12.19 00:27:59.263 2019.12.13 00:00:00   Check3() = true
2019.12.19 00:27:59.263 2019.12.13 00:00:00   Check4() = true
2019.12.19 00:27:59.263 2019.12.13 00:00:00   Check5() = true
2019.12.19 00:27:59.263 2019.12.13 00:00:00   Check6() = true
 
fxsaber:

Go for it. But I should point out straight away that any execution at last-price in the Tester is a mistake.

I've written to you in person.

Naturally, execution by flipper is meaningless (nonsense).

 
Sergey Chalyshev:

Can you test on a stock futures e.g. Si ?


Better. On real ticks, but TP is executed on fins.

 
fxsaber:

Not good.

Nah, there's something wrong with your tester. How do you test on all ticks or real ticks?

Try it on Si.

At 9:45 the market is still closed, anything can be there at that time, you have to open after 10:01.
 
Sergey Chalyshev:

If an exchange symbol and a netting account, only then will the limit at the current price be accepted.

Unfortunately, all marques (including TP) are executed on flippers. Therefore, it is better not to use the markets in the Tester.

 
What about access to all the loaded bars from the tester? Answer me please. Or explain why this artificial restriction is needed.
 
Alexey Kravchenko:
So what about access to all the loaded bars from the tester? Answer me please. Or explain why this artificial limitation is needed.

To speed up testing 99% of EAs.

For the remaining 1%, a crutch can be inserted.