ObjectDelete failing

 

Hi!

I've an EA that creates some objects on the graph. These objects have fixed names saved in string arrays inside a struct. When OnDeinit is called, I call a function with a for loop that goes to ObjectFind every drawn object and, once located, ObjectDelete them. After that, I call ChartRedraw.

Unfortunately not always the process works. For some reason, some times when I remove the EA (thus calling OnDeinit AFAIK), at least some objects keep on the graph. And I don't understad why that happens.

My problem seems similar to this post: https://www.mql5.com/en/forum/138271 . In his case, though, it seems the problem was that the objects weren't always been created with the exact same name, thus the strategy with the #define worked. For me that's not the case: not only the objects are previously created inside an init() function and assigned to a specific name, so their names never change during the running of the EA, but when I get this problem and ask the Terminal to list all objects, there my remaining objects are with the correct names. So no errors there.

Here is the basic cleanup code:

void destroyOtherFigures()
{
   for (int aaa = 0; aaa < glActualNumOfOps; ++aaa)
   {
      if (ObjectFind(glChartID,glFigureIDs.statusLabels[aaa]) >= 0)
         ObjectDelete(glChartID,glFigureIDs.statusLabels[aaa]);
      
      if (ObjectFind(glChartID,glFigureIDs.startOpSigns[aaa]) >= 0)
         ObjectDelete(glChartID,glFigureIDs.startOpSigns[aaa]);
         
      if (ObjectFind(glChartID,glFigureIDs.stopGainSigns[aaa]) >= 0)
         ObjectDelete(glChartID,glFigureIDs.stopGainSigns[aaa]);
         
      if (ObjectFind(glChartID,glFigureIDs.stopLossSigns[aaa]) >= 0)
         ObjectDelete(glChartID,glFigureIDs.stopLossSigns[aaa]);
         
      if (ObjectFind(glChartID,glFigureIDs.opNumberSigns[aaa]) >= 0)
         ObjectDelete(glChartID,glFigureIDs.opNumberSigns[aaa]);   
   }
   
   if (ObjectFind(glChartID,glFigureIDs.decrementalClock) >= 0)
         ObjectDelete(glChartID,glFigureIDs.decrementalClock);
}

glActualNumOfOps has value assigned only once in the OnInit function. Same with glChartID. 

Could it be that ObjectFind is buggy? And thus I should move to the same iteration algorithm used in the mentioned forum thread?

Clean objects on chart period change?
Clean objects on chart period change?
  • 2012.02.28
  • www.mql5.com
Hello again, I would like to detect a timeframe change and clean all objects on the chart from my indicator...
Reason: