How to know when any object is deleted from chart? [Solved] - page 2

 
Samuel Manoel De Souza #:
Also, use the Styler in your Meta Editor before post the code. Just need click a button and that will organize your code.

ok noted, thanks

 
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   ChartSetInteger(0, CHART_EVENT_OBJECT_CREATE, true);
   ChartSetInteger(0, CHART_EVENT_OBJECT_DELETE, true);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
  {
   switch(id)
     {
      case CHARTEVENT_OBJECT_CREATE :
         OnObjectCreate(sparam);
         break;
      case CHARTEVENT_OBJECT_DELETE :
         OnObjectDelete(sparam);
         break;
      default:
         break;
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string MyObjectName = "";
void OnObjectCreate(const string name)
  {
   if(ObjectGetInteger(0, name, OBJPROP_TYPE) == OBJ_FIBO)
      MyObjectName = name;
// do something with the object
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnObjectDelete(const string name)
  {
   if(name == MyObjectName)
     {
      // do something
      
      // ---
      MyObjectName = "";
     }
  }
//+------------------------------------------------------------------+
 

You cannot check the object type once it is deleted.

So you need store the name of the object to know when it is deleted.

 
Samuel Manoel De Souza #:

Thank you very much sir, My problem Solved.