After some debugging and rewriting the code from scratch from a backup where it worked, I found that when it was working I was drawing the options up to 6 times because I put the line inside another loop, which shouldn't have been, and after every loop there was a ChartRedraw().
So, this gets me to a conclusion, it might be wrong though. The xSize of a LABEL won't change until the label is drawn by a ChartRedraw() because I am guessing it needs to draw the text to calculate its size. Only doing one ChartRedraw() is not enough because it gets to the ObjectGetInteeger line before the label has been drawn. After some tests I've seen that I need to do at least 2 times the CreateOptions which is a bunch of recrtangles with labels to get it well drawn. So it draws it wrong the first time, but the second time it "updates" with the correct information.
Has anyone experienced the same issue? Any idea to solve this without having to loop just to "win some time" to get the correct xSize? Because that doesn't seem a good solution for me. The only viable solution I see would be calculating myself the xSize with the length of the string, the font size and the font. Any other possible solutions?
Thank you.
https://www.mql5.com/en/forum/35582
Any moderator feel free to delete this post if considered necessary. Thank you and sorry for the inconvinience.

- 2014.08.19
- Irwan Adnan
- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I've been all morning stuck with this problem. My indicator has a function to draw a rectangle label and a label so it shows a label with background. The problem comes that when I use the ObjectGetInteger to get the xSize of the label to apply it to the rectangle label it doesn't work. Tried to debug many times and the value was always 0 except if I redraw the chart before getting the information. Even then, sometime it didn't work. The labels in which it happenned were random, not always the same. So I'm really lost not knowing what could be the problem.
Moreover, this function was working fine before I rewrite the code to do it in multiple charts at the same time which is the same but doing it in loop.
Here is the code. The two lines before setting it was just to know while debugging if the info was right or not, in the string case is always right, in the x_size case is not, depending on chartRedraw() and somehting random I can't find:
And here is the loop where I am doing it