Hide indicator display on backtest MT5

 

In MT4 to hide indicator during backtesting using this script inside EA :

int init() {
   HideTestIndicators(TRUE);
   return (0);
}

How to write similar code in MT5?

 
achidayat:

In MT4 to hide indicator during backtesting using this script inside EA :

How to write similar code in MT5?

Hi achidayat, 

It's  https://www.mql5.com/en/docs/runtime/testing#indicatorrelease

:D 

Documentation on MQL5: MQL5 programs / Testing Trading Strategies
  • www.mql5.com
MQL5 programs / Testing Trading Strategies - Documentation on MQL5
 

Thank you, but I can't apply to this EA (example is part of multi currency EA "exp_tema"). How can I apply to this EA? Full EA in here : https://www.mql5.com/en/code/450

//+------------------------------------------------------------------+
//| Custom TradeSignalCounter() function                             |
//+------------------------------------------------------------------+
bool TradeSignalCounter(int Number,
                        string Symbol_,
                        bool Trade,
                        int period,
                        ENUM_APPLIED_PRICE ApPrice,
                        bool &UpSignal[],
                        bool &DnSignal[],
                        bool &UpStop[],
                        bool &DnStop[])
  {
//--- check if trade is prohibited
   if(!Trade)return(true);

//--- declare variable to store final size of variables arrays
   static int Size_=0;

//--- declare array to store handles of indicators as static variable
   static int Handle[];

   static int Recount[],MinBars[];
   double TEMA[4],dtema1,dtema2;

//--- initialization
   if(Number+1>Size_) // Entering the initialization block only on first start
     {
      Size_=Number+1; // For this number entering the block is prohibited

      //--- change size of variables arrays
      ArrayResize(Handle,Size_);
      ArrayResize(Recount,Size_);
      ArrayResize(MinBars,Size_);

      //--- determine minimum number of bars, sufficient for calculation 
      MinBars[Number]=3*period;

      //--- setting array elements to 0
      DnSignal[Number] = false;
      UpSignal[Number] = false;
      DnStop  [Number] = false;
      UpStop  [Number] = false;

      //--- use array as timeseries
      ArraySetAsSeries(TEMA,true);

      //--- get indicator's handle
      Handle[Number]=iTEMA(Symbol_,0,period,0,ApPrice);
     }

//--- check if number of bars is sufficient for calculation 
   if(Bars(Symbol_,0)<MinBars[Number])return(true);
//--- get trade signals 
   if(IsNewBar(Number,Symbol_,0) || Recount[Number]) // Entering the block on bar change or on failed copying of data
     {
      DnSignal[Number] = false;
      UpSignal[Number] = false;
      DnStop  [Number] = false;
      UpStop  [Number] = false;

      //--- using indicator's handles, copy values of indicator's
      //--- buffers into static array, specially prepared for this purpose
      if(CopyBuffer(Handle[Number],0,0,4,TEMA)<0)
        {
         Recount[Number]=true; // As data were not received, we should return 
                               // into this block (where trade signals are received) on next tick!
         return(false);        // Exiting the TradeSignalCounter() function without receiving trade signals
        }

      //--- all copy operations from indicator buffer are successfully completed
      Recount[Number]=false; // We may not return to this block until next change of bar

      int Digits_=int(SymbolInfoInteger(Symbol_,SYMBOL_DIGITS)+4);
      dtema2 = NormalizeDouble(TEMA[2] - TEMA[3], Digits_);
      dtema1 = NormalizeDouble(TEMA[1] - TEMA[2], Digits_);

      //---- determining the input signals
      if(dtema2 > 0 && dtema1 < 0) DnSignal[Number] = true;
      if(dtema2 < 0 && dtema1 > 0) UpSignal[Number] = true;

      //---- determining the output signals
      if(dtema1 > 0) DnStop[Number] = true;
      if(dtema1 < 0) UpStop[Number] = true;
     }
//----+
   return(true);
  }
Exp_TEMA
  • votes: 6
  • 2011.09.29
  • Nikolay Kositsin | English Russian Chinese Spanish Portuguese
  • www.mql5.com
Multi-currency trend following expert system using the Triple Exponential Moving Average technical indicator.
 
achidayat:

Thank you, but I can't apply to this EA (example is part of multi currency EA "exp_tema"). How can I apply to this EA? Full EA in here : https://www.mql5.com/en/code/450

Hi achidayat,

Did you ever read the explanation on that link https://www.mql5.com/en/docs/runtime/testing#indicatorrelease ?. It tell exactly where to put it !!!

:|  

Documentation on MQL5: MQL5 programs / Testing Trading Strategies
  • www.mql5.com
MQL5 programs / Testing Trading Strategies - Documentation on MQL5
 
onewithzachy:

Hi achidayat,

Did you ever read the explanation on that link https://www.mql5.com/en/docs/runtime/testing#indicatorrelease ?. It tell exactly where to put it !!!

:|  

yes. If I apply to EA single currency like this, it work :

bool   hided=true;
int    TEMA;
//+-----------------------------------+
void OnInit()
  {
   TEMA=iTEMA(NULL,0,period,0,ApPrice)
  }
//+-----------------------------------+
void OnDeinit(const int reason){
   bool hidden=IndicatorRelease(TEMA);
   if(hided) Print("IndicatorRelease() successfully completed");
   else Print("IndicatorRelease() returned false. Error code ",GetLastError());
}

But if I apply to multicurrency like this, it not work

bool hided = true;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
   {
    bool hidden=IndicatorRelease(Handle[Number]);
    if(hided) Print("IndicatorRelease() successfully completed");
    else Print("IndicatorRelease() returned false. Error code ",GetLastError());
   }
//+------------------------------------------------------------------+
//| Custom TradeSignalCounter() function                             |
//+------------------------------------------------------------------+
bool TradeSignalCounter(int Number,
                        string Symbol_,
                        bool Trade,
                        int period,
                        ENUM_APPLIED_PRICE ApPrice,
                        bool &UpSignal[],
                        bool &DnSignal[],
                        bool &UpStop[],
                        bool &DnStop[])
  {
//--- check if trade is prohibited
   if(!Trade)return(true);

//--- declare variable to store final size of variables arrays
   static int Size_=0;

//--- declare array to store handles of indicators as static variable
   static int Handle[];

   static int Recount[],MinBars[];
   double TEMA[4],dtema1,dtema2;

//--- initialization
   if(Number+1>Size_) // Entering the initialization block only on first start
     {
      Size_=Number+1; // For this number entering the block is prohibited

      //--- change size of variables arrays
      ArrayResize(Handle,Size_);
      ArrayResize(Recount,Size_);
      ArrayResize(MinBars,Size_);

      //--- determine minimum number of bars, sufficient for calculation 
      MinBars[Number]=3*period;

      //--- setting array elements to 0
      DnSignal[Number] = false;
      UpSignal[Number] = false;
      DnStop  [Number] = false;
      UpStop  [Number] = false;

      //--- use array as timeseries
      ArraySetAsSeries(TEMA,true);

      //--- get indicator's handle
      Handle[Number]=iTEMA(Symbol_,0,period,0,ApPrice);
     }

//--- check if number of bars is sufficient for calculation 
   if(Bars(Symbol_,0)<MinBars[Number])return(true);
//--- get trade signals 
   if(IsNewBar(Number,Symbol_,0) || Recount[Number]) // Entering the block on bar change or on failed copying of data
     {
      DnSignal[Number] = false;
      UpSignal[Number] = false;
      DnStop  [Number] = false;
      UpStop  [Number] = false;

      //--- using indicator's handles, copy values of indicator's
      //--- buffers into static array, specially prepared for this purpose
      if(CopyBuffer(Handle[Number],0,0,4,TEMA)<0)
        {
         Recount[Number]=true; // As data were not received, we should return 
                               // into this block (where trade signals are received) on next tick!
         return(false);        // Exiting the TradeSignalCounter() function without receiving trade signals
        }

      //--- all copy operations from indicator buffer are successfully completed
      Recount[Number]=false; // We may not return to this block until next change of bar

      int Digits_=int(SymbolInfoInteger(Symbol_,SYMBOL_DIGITS)+4);
      dtema2 = NormalizeDouble(TEMA[2] - TEMA[3], Digits_);
      dtema1 = NormalizeDouble(TEMA[1] - TEMA[2], Digits_);

      //---- determining the input signals
      if(dtema2 > 0 && dtema1 < 0) DnSignal[Number] = true;
      if(dtema2 < 0 && dtema1 > 0) UpSignal[Number] = true;

      //---- determining the output signals
      if(dtema1 > 0) DnStop[Number] = true;
      if(dtema1 < 0) UpStop[Number] = true;
     }
//----+
   return(true);
  }


 
achidayat:

yes. If I apply to EA single currency like this, it work :

But if I apply to multicurrency like this, it not work


Hi achidayat,

This TradeSignalCounter() function, where do you call it ? IMHO, the indicator handle should be called in OnInit().

:| 

 
onewithzachy:

Hi achidayat,

This TradeSignalCounter() function, where do you call it ? IMHO, the indicator handle should be called in OnInit().

:| 

According to this multicurrency EA this function call in OnTick() function

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- declare variables arrays for trade signals  
   static bool UpSignal[12],DnSignal[12],UpStop[12],DnStop[12];

//--- get trade signals
   TradeSignalCounter(0,Symb0,Trade0,Per0,ApPrice0,UpSignal,DnSignal,UpStop,DnStop);
   TradeSignalCounter(1,Symb1,Trade1,Per1,ApPrice1,UpSignal,DnSignal,UpStop,DnStop);
   TradeSignalCounter(2,Symb2,Trade2,Per2,ApPrice2,UpSignal,DnSignal,UpStop,DnStop);
   TradeSignalCounter(3,Symb3,Trade3,Per3,ApPrice3,UpSignal,DnSignal,UpStop,DnStop);
   TradeSignalCounter(4,Symb4,Trade4,Per4,ApPrice4,UpSignal,DnSignal,UpStop,DnStop);
   TradeSignalCounter(5,Symb5,Trade5,Per5,ApPrice5,UpSignal,DnSignal,UpStop,DnStop);
   TradeSignalCounter(6,Symb6,Trade6,Per6,ApPrice6,UpSignal,DnSignal,UpStop,DnStop);
   TradeSignalCounter(7,Symb7,Trade7,Per7,ApPrice7,UpSignal,DnSignal,UpStop,DnStop);
   TradeSignalCounter(8,Symb8,Trade8,Per8,ApPrice8,UpSignal,DnSignal,UpStop,DnStop);
   TradeSignalCounter(9,Symb9,Trade9,Per9,ApPrice9,UpSignal,DnSignal,UpStop,DnStop);
   TradeSignalCounter(10,Symb10,Trade10,Per10,ApPrice10,UpSignal,DnSignal,UpStop,DnStop);
   TradeSignalCounter(11,Symb11,Trade11,Per11,ApPrice11,UpSignal,DnSignal,UpStop,DnStop);

You can find full source code in this link : https://www.mql5.com/en/code/450

Exp_TEMA
  • votes: 6
  • 2011.09.29
  • Nikolay Kositsin | English Russian Chinese Spanish Portuguese
  • www.mql5.com
Multi-currency trend following expert system using the Triple Exponential Moving Average technical indicator.
 
achidayat:

According to this multicurrency EA this function call in OnTick() function

You can find full source code in this link : https://www.mql5.com/en/code/450

Hi achidayat,

I see ... thank you for the links -  my apology I missed that link earlier, maybe you should also post your questions on that code base and this article as well "Creating an Expert Advisor, which Trades on a Number of Instruments".

Regarding hiding indicator, maybe you should get those handle OnInit(), so IndicatorRelease() can works correctly - maybe.

:D 

 

If you want to hide indicators created inside an EA, then before you create the handle for an indicator that you do not want to be shown during testing you need to tell the EA to keep the indicators hidden.  In MT5 this is done with the TesterHideIndicators() function call.

Maybe use something like this in your OnInit(), or just before your indicator creation:


   if(IS_DEBUG_MODE) // debug mode 

      TesterHideIndicators(false); // allow the indicators to be shown in Debug Mode

   else

      TesterHideIndicators(true); // hide the indicators at all other times

 

Hi,

How can I hide indicators in "visual mode" of back test in Mt5?

Reason: