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

 

How can I understand from the EA in the tester the simulation mode used?

 
Ilya Malev #:

How can I understand from the EA in the tester the simulation mode used?

There is no way by standard means. The book suggests a workaround.
Учебник по MQL5: Генерация тиков в тестере / Автоматизация торговли
Учебник по MQL5: Генерация тиков в тестере / Автоматизация торговли
  • www.mql5.com
Наличие обработчика OnTick в эксперте не является обязательным для того, чтобы его можно было подвергнуть проверке в тестере. Советник может...
 
Ilya Malev #:

How can I understand from the EA in the tester the simulation mode used?

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

int OnInit()
{
  string Settings;
  
  const int Model = MTTESTER::GetSettings(Settings) ? (int)MTTESTER::GetValue(Settings, "Model") : -1;
  
  Print(Model);
  
  return(INIT_FAILED);
}

By analogy, all other values of the Tester are retrieved.


Forum on trading, automated trading systems and testing trading strategies

Features of mql5 language, subtleties and techniques of work

fxsaber, 2017.11.23 00:21

// Returns true only if the real ticks mode is selected (in the tester).
// At least one OnTick must be called by the tester before use
bool IsRealTicks( void )
{
  MqlTick Tick;
  
  return(SymbolInfoTick(_Symbol, Tick) && (Tick.volume || !(Tick.flags & TICK_FLAG_LAST)));
}


Example of use

// The Expert Advisor will be tested only in real ticks mode
void OnTick()
{
  static bool IsRemove = true;
  
  if (IsRemove)
  {
    IsRemove = MQLInfoInteger(MQL_TESTER) && !IsRealTicks();
    
    if (IsRemove)
    {
      Print("Real ticks mode is needed!");
      
      ExpertRemove();
      
      return;
    }
  }
  
  //........
}
How to do it in OnInit (without OnTick) - I don't know.

 
Do I understand correctly that the check of the margin sufficiency of an open pending order in the"Open Price Only" mode is made at the opening price of the bar following the bar of this order activation, while in the All Tick/Real Tick mode, this check is made at the moment when the current price crosses the opening price of this order inside the bar, on which it is actually opened? Thus, if the "no money" event occurs at the triggering of this order "in its place" inside the bar where it was triggered, but the "no money"/"margin call" event does not occur at the opening level of the next TF bar, corresponding to the TF of the test in the "Opening Prices Only" mode, then the test in the "Opening Prices Only" mode passes with flying colours, while the same test in the "All Ticks"/"Real Ticks" mode fails with the "no money" error?
 
Ilya Malev #:
Do I understand correctly that the check of the margin sufficiency of an open pending order in the"Open Price Only" mode is made at the opening price of the bar following the bar of this order activation, while in the All Tick/Real Tick mode, this check is made at the moment when the current price crosses the opening price of this order inside the bar, on which it is actually opened? Thus, if the "no money" event occurs at the triggering of this order "in its place" inside the bar where it was triggered, but the "no money"/"margin call" event does not occur at the opening level of the next TF bar, corresponding to the TF of the test in the "Opening Prices Only" mode, then the test in the "Opening Prices Only" mode passes with flying colours, while the same test in the "All Ticks"/"Real Ticks" mode fails with the "no money" error?

That's one way to say it, but the underlying issue is that all you have in Open Prices Only mode are open prices. Therefore, your simulated trades are executed at open prices only. Basically, everything is horrendously offset. This is why that mode is recommended only for EA's that explicitly control for bar open price.

Personally, I've never used Open Prices Only mode and likely never will--especially when M1 OHLC mode is virtually just as fast.

 
Ryan L Johnson #:
the main problem is that in the "Opening Prices Only" mode you only have opening prices.
In the "Open Prices Only" mode you have the high/low of the previous candle, taking into account which pending orders are opened or not opened without slippage.
 
Ilya Malev #:
In the "Open Prices Only" mode you have the high/low of the previous candle, taking into account which pending orders are opened or not opened without slippage.

In the Help documentation, I see what you mean regarding OHLC but then I also see a warning about slippage of stops and pendings:

"In this mode, OHLC prices of bars of the timeframe selected for testing are generated. The Expert Advisor function OnTick() is executed only at the beginning of the bar (at the Open price). Due to this feature, Stop Levels and pending orders may trigger at a price different from the specified one (especially when testing at higher timeframes). But this allows you to quickly run an evaluation test of an Expert Advisor."

Real and Generated Ticks - Algorithmic Trading, Trading Robots - MetaTrader 5 Help
Real and Generated Ticks - Algorithmic Trading, Trading Robots - MetaTrader 5 Help
  • www.metatrader5.com
Ticks are required for testing and optimizing Expert Advisors, because they use tick data for operation. Testing can be performed on real ticks...
 
Ryan L Johnson #:
I see in the help documentation that you are referring to OHLC, but then I also see a warning about slippage of stops and pending orders:

Don't believe everything they write on the fences.


#include <Trade/Trade.mqh>
CTrade trade;


void OnTick(void)
{
   static bool set=false;
   
   if(!set)
   {
      double price1=SymbolInfoDouble(_Symbol, SYMBOL_ASK)+SymbolInfoDouble(_Symbol, SYMBOL_POINT)*100;
      double tp1=price1+SymbolInfoDouble(_Symbol, SYMBOL_POINT)*1000;
      double sl1=price1-SymbolInfoDouble(_Symbol, SYMBOL_POINT)*1000;

      double price2=SymbolInfoDouble(_Symbol, SYMBOL_BID)-SymbolInfoDouble(_Symbol, SYMBOL_POINT)*100;
      double tp2=price2-SymbolInfoDouble(_Symbol, SYMBOL_POINT)*1000;
      double sl2=price2+SymbolInfoDouble(_Symbol, SYMBOL_POINT)*1000;
   
      trade.BuyStop(1.0, price1, _Symbol, sl1, tp1);
      trade.SellStop(1.0, price2, _Symbol, sl2, tp2);

      set=true;
   }
}
 
Ilya Malev #:

Don't believe everything they write on the fences.

Ah ha. The operative phrase in the Help documentation is "especially when testing at higher timeframes."

Clearly, H1 is not a higher timeframe.

 

Hi! I put any robot, symbol, TF, modelling type in the tester... I get an error: no history data. At the same time in the Symbols menu (Ctrl+U) the data of all TFs (including the minute one) are loaded. What can be the problem and how to fix it?