Write a text on a specific coordinate of chart

 

I want to get the output result of a function and show it on the chart:

  ObjectCreate(pastaverage, OBJ_LABEL, 0, 0, 0);
   string value1=DoubleToStr(checkaverage(), 7);
   ObjectSetText(pastaverage, "Average of previous bars:"+value1, 15, "Arial", CornflowerBlue);  
   ObjectSet("ObjName", OBJPROP_CORNER, 0);  
  ObjectSet(pastaverage, x2, 50);
  ObjectSet(pastaverage, y2, 50);


 the code above returns no error and also no text on the chart.

pastaverage is the name for my object. and it is defined as a string.

checkaverage() is a function that returns a double output.

x2 and y2 are integers that are defined above. 

 

Can you see it in the Objects List?   CTRL + B

You code doesn't actually check any return codes, so you might want to change that to help.

 
   ObjectCreate(objname4, OBJ_LABEL, 0, 0, 0);
   string value1=DoubleToStr(checkaverage(), 7);
   ObjectSetText(objname4, "Average of previous bars:"+value1, 15, "Arial", CornflowerBlue);  
   ObjectSet("ObjName", OBJPROP_CORNER, 0);  
  ObjectSet(objname4, x2, 50);
  ObjectSet(objname4, y2, 50);


      ObjectCreate(objname1, OBJ_LABEL, 0, 0, 0);
      string value2=DoubleToStr(checkcurrentfraction(), 7);
        ObjectSetText(objname1, "current fraction:"+value2, 15, "Arial", CornflowerBlue);    
   ObjectSet(objname1, x3, 50);
  ObjectSet(objname1, y3, 50);

Now I have two objects on my chart. But the second prints exactly on the previous one.
x2=50

y2=60

 x3=50

y3=80
=========
these are the coordinates where the two objects must be written. 

 
Morteza Khorasani:
   ObjectCreate(objname4, OBJ_LABEL, 0, 0, 0);
   string value1=DoubleToStr(checkaverage(), 7);
   ObjectSetText(objname4, "Average of previous bars:"+value1, 15, "Arial", CornflowerBlue);  
   ObjectSet("ObjName", OBJPROP_CORNER, 0);  
  ObjectSet(objname4, x2, 50);
  ObjectSet(objname4, y2, 50);


      ObjectCreate(objname1, OBJ_LABEL, 0, 0, 0);
      string value2=DoubleToStr(checkcurrentfraction(), 7);
        ObjectSetText(objname1, "current fraction:"+value2, 15, "Arial", CornflowerBlue);    
   ObjectSet(objname1, x3, 50);
  ObjectSet(objname1, y3, 50);

Now I have two objects on my chart. But the second prints exactly on the previous one.
x2=50

y2=60

 x3=50

y3=80
=========
these are the coordinates where the two objects must be written. 


Please read the documentacion about ObjectSet:


   bool  ObjectSet(
   string   object_name,   // object name
   int      index,         // property index
   double   value          // value
   );


In the second parameter of ObjectSet() function, you have to use:

OBJPROP_XDISTANCE

102

int

Integer value to set/get anchor X distance object property in pixels (see note)

OBJPROP_YDISTANCE

103

int

Integer value is to set/get anchor Y distance object property in pixels (see note)



And in the third parameter you specify the desired value.

Regards.

Object Properties - Objects Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
Object Properties - Objects Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
Object Properties - Objects Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
 
Jose Francisco Casado Fernandez:


Please read the documentacion about ObjectSet:


And in the third parameter you specify the desired value.

Regards.

Wow, you answered mql4 question now !
 
   ObjectCreate(objname4, OBJ_LABEL, 0, 0, 0);
   string value1=DoubleToStr(checkaverage(), 7);
   ObjectSetText(objname4, "Average of previous bars:"+value1, 15, "Arial", CornflowerBlue);  
   ObjectSet("ObjName", OBJPROP_CORNER, 0);  
  ObjectSet(objname4, x2, 50);
  ObjectSet(objname4, y2, 50);


      ObjectCreate(objname1, OBJ_LABEL, 0, 0, 0);
      string value2=DoubleToStr(checkcurrentfraction(), 7);
        ObjectSetText(objname1, "current fraction:"+value2, 15, "Arial", CornflowerBlue);    
   ObjectSet(objname1, x3, 50);
  ObjectSet(objname1, y3, 50);

I do not know what are the numbers 50 after x2,y2 and x3,y3.

by changing the x2,y2,x3,y3. there is no change .

I have already two text which are printed at the same position 

 
Alain Verleyen:
Wow, you answered mql4 question now !

Yes, it's Christmas, hahaha. :-)).


Regards.

 
Morteza Khorasani:
   ObjectCreate(objname4, OBJ_LABEL, 0, 0, 0);
   string value1=DoubleToStr(checkaverage(), 7);
   ObjectSetText(objname4, "Average of previous bars:"+value1, 15, "Arial", CornflowerBlue);  
   ObjectSet("ObjName", OBJPROP_CORNER, 0);  
  ObjectSet(objname4, x2, 50);
  ObjectSet(objname4, y2, 50);


      ObjectCreate(objname1, OBJ_LABEL, 0, 0, 0);
      string value2=DoubleToStr(checkcurrentfraction(), 7);
        ObjectSetText(objname1, "current fraction:"+value2, 15, "Arial", CornflowerBlue);    
   ObjectSet(objname1, x3, 50);
  ObjectSet(objname1, y3, 50);

I do not know what are the numbers 50 after x2,y2 and x3,y3.

by changing the x2,y2,x3,y3. there is no change .

I have already two text which are printed at the same position 


  ObjectSet(objname1, OBJPROP_XDISTANCE, x3);
  ObjectSet(objname1, OBJPROP_YDISTANCE, y3);
 
Thank you . it worked.
 
Morteza Khorasani:
Thank you . it worked.
Perfect. I'm glad. Happy New Year 2017.
 
Please use the link button (control-K.) for links Use
the link button See the difference: https://telegram.me/joinchat/BpnlGz8fEhBueF5beue3Kw
Reason: