Download MetaTrader 5

Deleting Objects/Label from chart

To add comments, please log in or register
salexes
812
salexes  

Hello,

One of the indicators I am using in my EA is printing text on the chart, is it possible to automatically remove such text ? I do not have the mq4 file for that indicator.

 

Any help is appreciated!

 regards,

salexes 

Carl Schreiber
7464
Carl Schreiber  
Either mark it (mause click) and press del or to see and to manage all press Ctrl+B on the chart.
salexes
812
salexes  
Carl Schreiber:
Either mark it (mause click) and press del or to see and to manage all press Ctrl+B on the chart.
I want to automatically remove it when the expert advisor starts. 
whroeder1
16278
whroeder1  
Fix your indicator.
salexes
812
salexes  
salexes:

I do not have the mq4 file for that indicator.

whroeder1:
Fix your indicator.
How do I do that without the mq4 of it?
whroeder1
16278
whroeder1  
You can't. Create another indicator or modify your EA, or remove your indicator.
salexes
812
salexes  

Got it. 

Used one of your answers from another thread:

 

    for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--){
        string on = ObjectName(iObj);
        if (StringFind(on, "ccline") == 0)  ObjectDelete(on);
        }  

 Thank you.

honest_knave
Moderator
2297
honest_knave  

If you want to automate the process, the best option is what whroeder1 suggests i.e. create a new indicator or modify the EA.

If you can't create a new indicator, the "least ugly" option is to recode your EA to delete ccline3 whenever it is created.

If ccline3 only gets created once per initialization, it shouldn't be too much of a problem.

But, if the indicator keeps trying to recreate ccline3 every tick, you're going to end up in a permanent battle between your EA and this indicator.

If you want to give it a go, add this to your OnInit():

ChartSetInteger(0,CHART_EVENT_OBJECT_CREATE,true);

Then add this (or merge it, if you are already using OnChartEvent in your EA):

void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
  {
   string prefix = "ccline";
   if(id==CHARTEVENT_OBJECT_CREATE && StringSubstr(sparam,0,StringLen(prefix))==prefix)
     {
      ObjectDelete(0,sparam);
      Print("Deleted ",sparam);
     }
  }

 

I've added a print statement so you can see how frequently ccline3 is being deleted.

Check the Experts log to see how often ccline3 is being deleted. 

salexes
812
salexes  
honest_knave:

If you want to automate the process, the best option is what whroeder1 suggests i.e. create a new indicator or modify the EA.

If you can't create a new indicator, the "least ugly" option is to recode your EA to delete ccline3 whenever it is created.

If ccline3 only gets created once per initialization, it shouldn't be too much of a problem.

But, if the indicator keeps trying to recreate ccline3 every tick, you're going to end up in a permanent battle between your EA and this indicator.

If you want to give it a go, add this to your OnInit():

ChartSetInteger(0,CHART_EVENT_OBJECT_CREATE,true);

Then add this (or merge it, if you are already using OnChartEvent in your EA):

void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
  {
   string obj_name = "ccline3";
   if(id==CHARTEVENT_OBJECT_CREATE && sparam==obj_name)
     {
      ObjectDelete(0,obj_name);
      Print("Deleted ",obj_name);
     }
  }

I've added a print statement so you can see how frequently ccline3 is being deleted.

Check the Experts log to see how often ccline3 is being deleted. 

Thank you, this solution works perfect.
honest_knave
Moderator
2297
honest_knave  
salexes:
Thank you, this solution works perfect.
I've modified my code above because I saw from your last post there are multiple objects with the prefix "ccline"
To add comments, please log in or register