ObjectSetText problem

 

How can I show more than 1 line of string using ObjectSetText function? Please see my code which I have borrowed from another trader on this Forum : https://www.mql5.com/en/code/10341. In fact, I need to show the number of open orders on 1 line and another line shows BID and ASK. I know I could show all the information in one line, but, for other purposes I want to show 2 lines.


ObjectCreate("word", OBJ_LABEL, 0, 0, 0);
ObjectSet("word", OBJPROP_CORNER, right_left);
ObjectSet("word", OBJPROP_XDISTANCE, x_distance);
ObjectSet("word", OBJPROP_YDISTANCE, y_distance);
string comment=StringConcatenate("You have ",OrdersTotal()," open trades.");
ObjectSetText("word", comment, word_size, "Times New Roman", word_color);


 
Draw a second label underneath the first.
 
RaptorUK:
Draw a second label underneath the first.

You mean like this:

int word_size = 14;
color word_color = Yellow;
bool right_left = false;
string disp_price;
int x_distance = 450;
int y_distance = 5;

ObjectCreate("word", OBJ_LABEL, 0, 0, 0);
ObjectSet("word", OBJPROP_CORNER, right_left);
ObjectSet("word", OBJPROP_XDISTANCE, x_distance);
ObjectSet("word", OBJPROP_YDISTANCE, y_distance);
ObjectSet("word1", OBJPROP_XDISTANCE, x_distance);
ObjectSet("word1", OBJPROP_YDISTANCE, y_distance+1);
//================================================
string comment=StringConcatenate("You have ",OrdersTotal()," open trades.");
string comment1=StringConcatenate("ASK=",ASK," BID=",BID);
ObjectSetText("word", comment, word_size, "Times New Roman", word_color);
ObjectSetText("word1", comment1, word_size, "Times New Roman", word_color);
 
zaffrono:

You mean like this:


Yep, something like that . . . give it a go, adjust and try again . . . :-)
 
I just did and it is not working out. what could be the problem?
 
zaffrono:
I just did and it is not working out. what could be the problem?
Ah . . you need to create the 2nd label . . . ObjectCreate()
 
   ObjectCreate("mytext", OBJ_LABEL,0,0,0);
   ObjectSet("mytext",OBJPROP_XDISTANCE,100);
   ObjectSet("mytext",OBJPROP_YDISTANCE,100);
   ObjectSetText("mytext","line1"+"\n"+"line2",9,"Times New Roman", Red);
   WindowRedraw();
   return(0);

i tried above and it didnt work.

looks like it wont support

 
jpbiznes:

i tried above and it didnt work.

looks like it wont support

Of course it won't . . . if you can't do it manually in MT4 using the Label tool you won't be able to do it programatically either . . .
 
zaffrono:

You mean like this:


Please someone help me out and tell me how I could do that. I am sure many many many traders in here are interested how to do this. Thank you in advance.
 
RaptorUK:
Ah . . you need to create the 2nd label . . . ObjectCreate()


int word_size = 14;
color word_color = Yellow;
int right_left = 0;    //  <-----   int not bool
string disp_price;
int x_distance = 450;
int y_distance = 5;

ObjectCreate("word", OBJ_LABEL, 0, 0, 0);
ObjectSet("word", OBJPROP_CORNER, right_left);
ObjectSet("word", OBJPROP_XDISTANCE, x_distance);
ObjectSet("word", OBJPROP_YDISTANCE, y_distance);

ObjectCreate("word1", OBJ_LABEL, 0, 0, 0);
ObjectSet("word1", OBJPROP_CORNER, right_left);
ObjectSet("word1", OBJPROP_XDISTANCE, x_distance);
ObjectSet("word1", OBJPROP_YDISTANCE, y_distance+15);
//================================================
string comment=StringConcatenate("You have ",OrdersTotal()," open trades.");
ObjectSetText("word", comment, word_size, "Times New Roman", word_color);

string comment1=StringConcatenate("ASK= ",Ask," BID= ",Bid);                 //  <--- Ask & Bid
ObjectSetText("word1", comment1, word_size, "Times New Roman", word_color);
 
cosmicbeing:
Hi Zaffrono,

You said - "looks like it wont support"... What does it not support?

Some of the code you are using ("\n") is line spacing for COMMENTS...not for labels (at least I've never seen them used in labels).

In the meantime...Raptor gave you the main clue...to do an ObjectCreate for each label.

And do each label separately in it's own section
...don't combine the text lines for different labels in one section...

So each TEXT LABEL section should have all the settings for just that TEXT....(x/y distance, ObjectCreate, ObjectSet, ObjectSetText)...

Also, keep your TEXT simple to start with. Don't use line spacing or anything that could cause problems.

Just get your labels working with the simple TEXT first...then add your more complicated TEXT later and experiment to get what you need in the labels.

Hope this helps,

Robert


Please note that the quotation "looks like it wont support" is by jpbiznes not me. I have provided the code on top of the page and Raptor said "Draw a second label underneath the first." which I did but it is not working. I have shown my code on top, so I appreciate if you or anyone else could change my code and show me what I did wrong. Thank you.
Reason: