How to Move & Replace text (Objects/Label) from the chart

To add comments, please log in or register
madolen
7
madolen  

Hello,


One of my indicators is printing text not good on the chart, I do not have the mq4 file for that indicator.




Can I move and replace text using another indicator?

I tried Object list, but not keep Also, this code did not work

ChartSetInteger(0,CHART_EVENT_OBJECT_CREATE,true);
void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
  {
   string obj_name = "Object";
   if(id==CHARTEVENT_OBJECT_CREATE && sparam==obj_name)
     {
  int replaced=StringReplace(obj_name,"text","new text");
  Print("Replaced: ", replaced,". Result=",obj_name);
     }
  }

I would appreciate any ideas?

Jose Francisco Casado Fernandez
5159
Jose Francisco Casado Fernandez  

Maybe the object is already created before you run this new indicator, but anyway using the StringReplace function here does not make sense. You should use ObjectSetString function:


   
 void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
  {
   string obj_name = "Object";
   if(id==CHARTEVENT_OBJECT_CREATE && sparam==obj_name)
     {
      ResetLastError(); 
      if(!ObjectSetString(0, obj_name, OBJPROP_TEXT, "new text"))
      PrintFormat("Unable to change: %s text. Error: %d", obj_name, GetLastError());
      else
      PrintFormat("%s text changed successfully", obj_name);
     }
  }
   
To add comments, please log in or register