OnChartEvent() CHART_EVENT_OBJECT_CREATE CHART_EVENT_OBJECT_DELETE

 

This code is in an EA


#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   bool check=ChartSetInteger(0,CHART_EVENT_OBJECT_CREATE,true);
   Print("CHART_EVENT_OBJECT_CREATE=",check);
   check=ChartSetInteger(0,CHART_EVENT_OBJECT_DELETE,true);
   Print("CHART_EVENT_OBJECT_DELETE=",check);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
  if(id==CHARTEVENT_OBJECT_CHANGE )
     {
     Print(sparam," Changed");
     
     }
  if(id==CHARTEVENT_OBJECT_DRAG )
     {
     Print(sparam," Dragged");
     
     }
  if(id==CHARTEVENT_OBJECT_CREATE)
     {
     Print(sparam," Created");
     
     }
  if(id==CHART_EVENT_OBJECT_DELETE)
     {
     Print(sparam," Deleted");
     
     }
 
 
//---
  }
//+------------------------------------------------------------------+


Now please tell me that I have made a stupid mistake.

CHARTEVENT_OBJECT_CHANGE and CHARTEVENT_OBJECT_DRAG seem to work perfectly

CHARTEVENT_OBJECT_CREATE works most of the time

CHART_EVENT_OBJECT_DELETE hardly ever works.

I would appreciate if you could try this code and let me know how it works for you.

Obviously if you can spot what I have done wrong, then I will appreciate that also.


thanks

 
  if(id==CHART_EVENT_OBJECT_DELETE)
     {
     Print(sparam," Deleted");
    
     }

Should be CHARTEVENT_OBJECT_DELETE.

 

CHARTEVENT_OBJECT_CREATE works most of the time

It seems to always works for me, but could depend of how you tested it ?

 
Alain Verleyen:
  if(id==CHART_EVENT_OBJECT_DELETE)
     {
     Print(sparam," Deleted");
    
     }

Should be CHARTEVENT_OBJECT_DELETE.

Thank you Alain,

I just couldn't see it.

It works now.

Maybe I should delete this topic to save my embarrassment :)

Nah, we all make mistakes and thank God we have someone like you to point them out.

Thanks again, I was going crazy.

 
Alain Verleyen:

It seems to always works for me, but could depend of how you tested it ?

It may be that in earlier test codes I had made the same mistake. When it wasn't working properly, I changed some code  and that bit seems to be ok now.
 
Keith Watford:

Thank you Alain,

I just couldn't see it.

It works now.

Maybe I should delete this topic to save my embarrassment :)

Nah, we all make mistakes and thank God we have someone like you to point them out.

Thanks again, I was going crazy.

Welcome. Just delete it if you want, I will not say it to anyone
 

An interesting thing I found which I didn't see documented anywhere (maybe it is)...

If you delete multiple objects, sparam on the chartevent is returned as *

If you delete multiple objects with the same prefix, sparam is still returned as *

If you delete multiple objects with the same prefix by using ObjectsDeleteAll(0,prefix) then sparam is returned as prefix*

 

Hi Devs, 

I have same problem. When I delete an Object from a chart, Chart event CHARTEVENT_OBJECT_DELETE does not work at all!!!

part of my code that checks for object delete is as below.

What do am I missing?!! 

if (id == CHARTEVENT_OBJECT_DELETE)
      {
      Comment(sparam); Print(sparam);
      FillLookBack();
      }

FillLookBack() is a function.

there is not any name on chart or journal when I delete an object! 

 
Jabir Ismaeili:

Hi Devs, 

I have same problem. When I delete an Object from a chart, Chart event CHARTEVENT_OBJECT_DELETE does not work at all!!!

part of my code that checks for object delete is as below.

What do am I missing?!! 

FillLookBack() is a function.

there is not any name on chart or journal when I delete an object! 

you don't show all your code, is this correctly located in OnChartEvent function?

show all of your OnChartEvent function

 
Jabir Ismaeili:

Hi Devs, 

I have same problem. When I delete an Object from a chart, Chart event CHARTEVENT_OBJECT_DELETE does not work at all!!!

part of my code that checks for object delete is as below.

What do am I missing?!! 

FillLookBack() is a function.

there is not any name on chart or journal when I delete an object! 

Where you able to figure what was the problem, currently having the same problem

void OnChartEvent(const int id,const long& lparam,const double& dparam,const string& sparam)
  {
   // Printing the value of "id" to comfirm if something or the ID for CHARTEVENT_OBJECT_DELETE is seen
      Print (id);
      if(id == CHARTEVENT_OBJECT_DELETE)
        {
            Print("Working Finally");
        }
  }

The Chart is not printing any value for "CHARTEVENT_OBJECT_DELETE", if you delete an object from the chart it does nothing hence there is no value for id, meaning the instance of id==CHARTEVENT_OBJECT_DELETE would not be seen.

 
Trapheal:

Where you able to figure what was the problem, currently having the same problem

The Chart is not printing any value for "CHARTEVENT_OBJECT_DELETE", if you delete an object from the chart it does nothing hence there is no value for id, meaning the instance of id==CHARTEVENT_OBJECT_DELETE would not be seen.

Have you enabled it in OnInit() ?

Reason: