This could help :

Documentation on MQL5: Object Functions / TextGetSize
- www.mql5.com
TextGetSize - Object Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Than you for your reply. But this won't be helpful to me in my situation. I am using Text Object. But I will give it a try.
jaffer wilson:
Than you for your reply. But this won't be helpful to me in my situation. I am using Text Object. But I will give it a try.
bool once = false; void OnTick() { //--- if (!once) { double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK); ask = ask + (double(100)*_Point); datetime now = TimeCurrent(); string textname = "Thisistext"; string texttodraw = "SAMPLETEXTNOW"; TextSetFont("Arial",10,0,0); uint w,h; TextGetSize(texttodraw,w,h); ObjectCreate(ChartID(),textname,OBJ_TEXT,0,now,ask); ObjectSetString(ChartID(),textname,OBJPROP_TEXT,texttodraw); ObjectSetString(ChartID(),textname,OBJPROP_FONT,"Arial"); ObjectSetInteger(ChartID(),textname,OBJPROP_FONTSIZE,10); ObjectSetInteger(ChartID(),textname,OBJPROP_COLOR,clrSeaGreen); Print("text width is ",IntegerToString(w)," and height is ",IntegerToString(h)); once = true; } }
IO 0 12:54:01.456 History EURUSD,M15: history begins from 2019.01.02 09:00 QH 0 12:54:01.469 Tester EURUSD,M15 (XMGlobal-MT5 2): generating based on real ticks MM 0 12:54:01.469 Tester testing with execution delay 251 milliseconds ON 0 12:54:01.469 Tester EURUSD,M15: testing of Experts\ObjTxt.ex5 from 2020.08.21 00:00 to 2020.08.23 00:00 started JJ 0 12:54:01.498 ObjTxt (EURUSD,M15) 2020.08.21 00:00:00 true FF 0 12:54:01.509 Ticks EURUSD : real ticks begin from 2019.03.29 00:00:00 LQ 0 12:54:01.525 ObjTxt (EURUSD,M15) 2020.08.21 00:00:00 text width is 70 and height is 10
Wow it worked. Thank you.
roshjardine:
Thank you for the beautiful example.
roshjardine:
nice +++
Forum on trading, automated trading systems and testing trading strategies
How to calculate the width of the text in OBJ_TEXT?
jaffer wilson, 2020.08.23 16:25
Wow it worked. Thank you.
you are welcome

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I have draw an object using OBJ_TEXT.
I have tried using the ObjectGetInteger(0, "name", OBJPROP_XSIZE); so that I will get the length of the text that is set using the OBJ_TEXT. But I get 0 in return.
I have read the documentation related to the OBJPROP_XSIZE, and OBJ_TEXT is not mentioned in the list of the object to which this property applies.
Hence, I get zero (0), in the output.
Now, please can someone help me find out the width of the text that I have placed?
I look forward to hear the answer to the problem.