Download MetaTrader 5

Write a text on a specific coordinate of chart

To add comments, please log in or register
Morteza Khorasani
111
Morteza Khorasani  

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. 

honest_knave
Moderator
2293
honest_knave  

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.

Morteza Khorasani
111
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. 

Jose Francisco Casado Fernandez
4411
Jose Francisco Casado Fernandez  
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
Alain Verleyen
Moderator
33800
Alain Verleyen  
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 !
Morteza Khorasani
111
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 

Jose Francisco Casado Fernandez
4411
Jose Francisco Casado Fernandez  
Alain Verleyen:
Wow, you answered mql4 question now !

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


Regards.

Jose Francisco Casado Fernandez
4411
Jose Francisco Casado Fernandez  
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);
Morteza Khorasani
111
Morteza Khorasani  
Thank you . it worked.
Jose Francisco Casado Fernandez
4411
Jose Francisco Casado Fernandez  
Morteza Khorasani:
Thank you . it worked.
Perfect. I'm glad. Happy New Year 2017.
whroeder1
16555
whroeder1  
Please use the link button (control-K.) for links Use
the link button See the difference: https://telegram.me/joinchat/BpnlGz8fEhBueF5beue3Kw
To add comments, please log in or register