The OnDeinit () method for an indicator, no longer exists in MQL5?

 

Hello,

The OnDeinit () method for an indicator, no longer exists in MQL5?


//+------------------------------------------------------------------+
//|                                                          ttt.mq5 |
//|                                   Copyright 2018, Pierre Rougier |
//|                                           www.apprendre-mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, Pierre Rougier"
#property link      "www.apprendre-mql5.com"
#property version   "1.00"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Pierre Rougier: The OnDeinit () method for an indicator, no longer exists in MQL5?
Where do you get that idea? Perhaps you should read the manual.
Type Function name Parameters Application Comment
int OnInit none Expert Advisors and indicators Init event handler. It allows to use the void return type.
void OnDeinit const int reason Expert Advisors and indicators Deinit event handler.
: : : : :
          MQL5 programs / Program Running - Reference on algorithmic/automated trading language for MetaTrader 5
 
Pierre Rougier:

Hello,

The OnDeinit () method for an indicator, no longer exists in MQL5?


Did you build this code from the wizard? If so, you may need to add it yourself.

OnDeinit() works for both Experts and Indicators.

void OnDeinit(const int reason)
{
    Print(StringFormat("%s(): reason [%d]", __FUNCTION__, reason));
}
 

Did you build this code from the wizard? 

Exactly.

Thanks,
Pierre

 
Anthony Garot #:

Did you build this code from the wizard? If so, you may need to add it yourself.

OnDeinit() works for both Experts and Indicators.

Is it useful to delete an handle in a indicator when we closing it? I do this in expert advisor writing 

//+------------------------------------------------------------------+
//| [FUNCTION] Deinitialization                                      |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   if(GIO != INVALID_HANDLE)
      IndicatorRelease(GIO);
  }
 
Milko Vivaldi #:

Is it useful to delete an handle in a indicator when we closing it? I do this in expert advisor writing 

The terminal is supposed to do this after an indicator or ea is removed from any chart, however, it is advisable to remove the handle yourself, yes.

 
For Tester, please check it this out