EA OnDeinit -EA comes attached to chart even if chart closed

 

Hello MQ4 community, I am having a weird situation. I have EA that has OnDeinit function, that works sometimes but other times it does not. Is there like a "session save" type of situation here ? I mean code I have is pretty straightforward as below:

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//---

for(int i = ObjectsTotal() - 1; i >= 0 ; i--)

     {

      if(StringFind(ObjectName(i), ObjPrefix) == 0)

         ObjectDelete(ObjectName(i));

     }

   Comment("");   

  }

//+------------------------------------------------------------------+

What am I doing wrong here ? 

I tried to even use both functions as below, still no luck. 

ObjectsDeleteAll(); 

    ExpertRemove();

    Comment("");


Simply, I would like to open a fresh chart without any objects on it, is there a better way ?

thanks in advance, cheers. 

 

Please edit your post and use the code button (Alt+S) when posting code.

Check the Experts tab. You possibly have a critical error in the EA and the EA is stopped without OnDeinit being called.

 
Nothing wrong with your deinit except it can be simplified.
void OnDeinit(const int reason){
   ObjectsDeleteAll(0, ObjPrefix);
   Comment("");
  }