MQL 5 Deinit not working

 
Hey guys, so I am experimenting MQL5 and I saw there is no more Deinit by default so you have to add it. I made a quick test of an indicator that display an object at OnInit but I want it to be removed when I remove the indicator so ObjectDelete. I added a OnDeinit func and put the ObjectDelete inside but for a mysterious reason the object created still doesn't get deleted when I remove the indicator o n Chart. Any help will be appreaciated. Thanks in advence.
//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window

#define EDIT_NAME "Edit"
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   //Create text field for symbol
  ObjectCreate(0, EDIT_NAME, OBJ_EDIT, 0, 0, 0);
  ObjectSetInteger(0, EDIT_NAME, OBJPROP_FONTSIZE, 10);
   ObjectSetInteger(0, EDIT_NAME, OBJPROP_XSIZE, 90);
   ObjectSetInteger(0, EDIT_NAME, OBJPROP_YSIZE, 25);
   ObjectSetInteger(0, EDIT_NAME, OBJPROP_XDISTANCE, 500);
   ObjectSetInteger(0, EDIT_NAME, OBJPROP_YDISTANCE, 65);
   ObjectSetInteger(0, EDIT_NAME, OBJPROP_COLOR, clrBlack);
   ObjectSetInteger(0, EDIT_NAME, OBJPROP_BGCOLOR, clrWhite);
   ObjectSetInteger(0, EDIT_NAME, OBJPROP_BORDER_COLOR, clrBlack);
   ObjectSetString(0, EDIT_NAME, OBJPROP_FONT, "Arial");
   ObjectSetInteger(0, EDIT_NAME, OBJPROP_CORNER, CORNER_LEFT_UPPER);
//---
   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);
  }
//+------------------------------------------------------------------+

void OnDeinit(const int reason)
{ObjectDelete(0, EDIT_NAME);
   }
 
Bryan Djoufack Nguessong:
Hey guys, so I am experimenting MQL5 and I saw there is no more Deinit by default so you have to add it. I made a quick test of an indicator that display an object at OnInit but I want it to be removed when I remove the indicator so ObjectDelete. I added a OnDeinit func and put the ObjectDelete inside but for a mysterious reason the object created still doesn't get deleted when I remove the indicator o n Chart. Any help will be appreaciated. Thanks in advence.

Hello,

After deleting the object, you should add ChartRedraw()
.. and the object will disappear from the chart.

void OnDeinit(const int reason)
{
  Print("Execute OnDeinit()");
  //--
  ResetLastError();
  if(ObjectDelete(0, EDIT_NAME)) 
  {
    Print("Object deleted."); 
    ChartRedraw(); 
  }
  else  
    Print("Object deletion has failed. Error code: ",GetLastError());
}

 
Yohana Parmi #:

Hello,

After deleting the object, you should add ChartRedraw()
.. and the object will disappear from the chart.

Thanks it helped. Please can you check this also? Another issue I have 

Indicator bugging on MT5 after Upgrading code to MQL5 from MQL4
Indicator bugging on MT5 after Upgrading code to MQL5 from MQL4
  • 2022.08.13
  • www.mql5.com
Hey guys. So I've upgraded a the code of overlaychart to have some buttons and all and it worked well on MT4. So I decided to port it to MT5...
 
Bryan Djoufack Nguessong #:

Thanks it helped.
Please can you check this also? Another issue I have 

Btw, if I do that, then freelancers will be disappointed in me.

Please use https://www.mql5.com/en/job 
You can find even better coders than me there.

Kind regards.

Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • 2022.08.13
  • www.mql5.com
The largest freelance service with MQL5 application developers
 
Yohana Parmi #:

Btw, if I do that, then freelancers will be disappointed in me.

Please use https://www.mql5.com/en/job 
You can find even better coders than me there.

Kind regards.

Okey thanks

Reason: