OnChartEvent() CHART_EVENT_OBJECT_CREATE CHART_EVENT_OBJECT_DELETE

To add comments, please log in or register
Keith Watford
Moderator
20312
Keith Watford  

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

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

Should be CHARTEVENT_OBJECT_DELETE.

Alain Verleyen
38646
Alain Verleyen  

CHARTEVENT_OBJECT_CREATE works most of the time

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

Keith Watford
Moderator
20312
Keith Watford  
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.

Keith Watford
Moderator
20312
Keith Watford  
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.
Alain Verleyen
38646
Alain Verleyen  
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
honest_knave
Moderator
2308
honest_knave  

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*

To add comments, please log in or register