Unable to delete CIndicator object

 

Hi,


I am trying to delete an indicator created using the class CiMA in MT5 with no success. Always when I recompile my indicator, the message "1 object of type CiMA left" appears in the experts tab.

Can somebody help me to delete correctly this object.


Thanks in advance.


My code is:

#include <Indicators/Trend.mqh>

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
//--- plot Buy
#property indicator_label1 "BuySell"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrBlue

//--- indicator buffers
double BuySellBuffer[];

CiMA m_MA;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   //Initialize the moving average indicator
   m_MA = new CiMA();
   m_MA.Create(Symbol(), PERIOD_D1, 5, 0, MODE_SMA, PRICE_CLOSE);
   
   return (INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(
   const int        rates_total,       // price[] array size 
   const int        prev_calculated,   // number of handled bars at the previous call 
   const int        begin,             // index number in the price[] array meaningful data starts from 
   const double&    price[])            // array of values for calculation 
{
   
   return (rates_total);
}

void OnDeinit(const int reason)
{
   m_MA.FullRelease();
   //delete m_MA;
}
Entdecken Sie neue Möglichkeiten des MetaTrader 5 mit MQL5 Gemeinschaft und Services
Entdecken Sie neue Möglichkeiten des MetaTrader 5 mit MQL5 Gemeinschaft und Services
  • 2024.02.01
  • www.mql5.com
MQL5: eine Sprache von Handelsstrategien, eingebaut in die Handelsplattform MetaTrader 5, mit der man eigene Handelsroboter, technische Indikatoren, Skripte und Funktionsbibliotheken
 

You mean you get that message when attaching and detaching the indicator, not when you compile. Uncomment the highlighted line.

void OnDeinit(const int reason)
{
   m_MA.FullRelease();
   //delete m_MA; ==> UNCOMMENT THIS LINE
}