Documentation on MQL5: Object Functions / ObjectSetString
OBJPROP_TEXT
Description of the object (the text contained in the object)
string
- www.mql5.com
Documentation on MQL5: Object Functions / ObjectSetString
OBJPROP_TEXT
Description of the object (the text contained in the object)
string
Thanks alot.It works perfectly
Hi,
I am passing double datatype onto function as below where the price variable represents a price point on a MT5 chart
double price; ObjectSetString(chart_ID,name,OBJPROP_TEXT,price);
During compilation I get a warning implicit conversion from 'number' to 'string' and I am ok with that as I expect the function ObjectSetString to convert the number to string and the number is displayed as string on my charts.
However,for easy reading of the converted string I would like to have the converted number into a string with comma separators so that if for instance I pass number 15577.5 onto the function,I would like it to be displayed with comma separators as 15,577.5 on the chart instead of the 15577.5 displayed currently.
How can I add such comma separators?
Thanks.
As the name of the ObjectSetString function states, it expects the parameter to be a "string", not a "double".
So, an implicit typecast will be applied if you use any other datatype besides a "string".
If you require a specific format, then use a proper conversion function such as DoubleToString or StringFormat.
However, if you require any kind of specialised formatting, then you will have to write your own formatting function.
Also, please use the CODE button (Alt-S) when inserting code.
Thanks alot.It works perfectly
Hi,
I am passing double datatype onto function as below where the price variable represents a price point on a MT5 chart
During compilation I get a warning implicit conversion from 'number' to 'string' and I am ok with that as I expect the function ObjectSetString to convert the number to string and the number is displayed as string on my charts.
However,for easy reading of the converted string I would like to have the converted number into a string with comma separators so that if for instance I pass number 15577.5 onto the function,I would like it to be displayed with comma separators as 15,577.5 on the chart instead of the 15577.5 displayed currently.
How can I add such comma separators?
Thanks.
Not sure if there is a simpler way, but you could write a function like this
string getCommaSepNumStr(double num, int decimals) { string numStr = DoubleToString(num, decimals); long numRadix = (int) floor(num); string numRadixStr = IntegerToString(numRadix); string numDecimalStr = StringSubstr(numStr, StringFind(numStr, ".")); string numCommaStr = ""; int commasAdded = 0; for(int i = StringLen(numRadixStr); i >= 0; i--) { if(((StringLen(numCommaStr) - commasAdded) % 3 == 0) && (StringLen(numCommaStr) > 0)) { numCommaStr = "," + numCommaStr; commasAdded++; } numCommaStr = StringSubstr(numRadixStr, i, 1) + numCommaStr; } numCommaStr += numDecimalStr; return(numCommaStr); }
string getCommaSepNumStr(double num, int decimals) { string numStr = DoubleToString(num, decimals); long numRadix = (int) floor(num); string numRadixStr = IntegerToString(numRadix); string numDecimalStr = StringSubstr(numStr, StringFind(numStr, ".")); string numCommaStr = ""; int commasAdded = 0; for(int i = StringLen(numRadixStr); i >= 0; i--) { if(((StringLen(numCommaStr) - commasAdded) % 3 == 0) && (StringLen(numCommaStr) > 0)) { numCommaStr = "," + numCommaStr; commasAdded++; } numCommaStr = StringSubstr(numRadixStr, i, 1) + numCommaStr; } numCommaStr += numDecimalStr; return(numCommaStr); }
Thanks a million.I really appreciate it R4tna
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have a mql5 code/program that creates horizontal lines (OBJ_HLINE).I am able to set other parameters of the horizontal line like name,font size,color among other parameters via code but cannot set the object description name through any function that I am aware of and I have to manually click on the properties of the line and add my desired text on Description on the textbox highlighted in yellow as shown in image attached.
Since I use my program to make many horizontal lines,its tedious having to manually add on each line the description on textbox as explained above and was hoping if one can give my some code syntax that I can add to my program to add descriptions as I create the lines using my code.
Thanks