Hi
You can set right alignment as the property of the objects and then I think the best option is to make your own “space distance” variable
Best Regards
Hello, the text OBJECT does not have right-justified properties, otherwise I would not have posted.
Hello everyone,
This topic is old, but there hasn't been a clear solution yet.
Here's an example.
obj.TextCreate(0, "n 1", 0, 245, 158, 250, 163, "Arial", "ON", clrYellow); // 245 must be adjusted further to the right! ObjectSetInteger(0,"n 1",OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER);
I hope I could help.
Regards, Igor
Hello everyone,
I am currently trying to develop a panel that requires aligning text with the right edge of a graphical background layer. I have been using the TextGetSize() function to calculate the width of the text and attempting to position the text by subtracting this width from the right edge X-coordinate of the background. However, the results are not accurate, and the text does not align with the right edge as expected.
Here is the code snippet I used:
obj.TextCreate(0, "n 1", 0, CalculateLeftAlignmentX(GetRightEdge(0, "n bitlabel"), "ON", 10), y + y_distance * 1, 10, "Arial", "ON", clrYellow);
obj.TextCreate(0, "n 2", 0, CalculateLeftAlignmentX(GetRightEdge(0, "n bitlabel"), "999", 10), y + y_distance * 2, 10, "Arial", "999", clrYellow);
obj.TextCreate(0, "n 3", 0, CalculateLeftAlignmentX(GetRightEdge(0, "n bitlabel"), "IC MARKETS", 10), y + y_distance * 3, 10, "Arial", "IC MARKETS", clrYellow);
int GetRightEdge(const int chart_ID, const string ref_name)
{
int ref_x = (int)ObjectGetInteger(chart_ID, ref_name, OBJPROP_XDISTANCE) + (int)ObjectGetInteger(chart_ID, ref_name, OBJPROP_XSIZE);
return ref_x;
}
int CalculateLeftAlignmentX(const int rightEdgeX, const string text, const int distance)
{
uint text_width, text_height;
TextGetSize(text, text_width, text_height);
int new_x = rightEdgeX - text_width - distance;
printf("%f",text_width);
return new_x;
}
Does anyone know a more accurate method to measure text width, or are there other techniques that can help achieve this alignment? Thank you for your help!
The issue is that TextGetSize() does not use the correct font and size unless you explicitly set them first.
Solution: Call TextSetFont("Arial", 10) before TextGetSize() to match the font and size used in your TextCreate . Otherwise, it measures using default settings, which leads to incorrect alignment.
Also, make sure to round or floor values properly when converting to pixel positions to avoid offset errors.

- 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 everyone,
I am currently trying to develop a panel that requires aligning text with the right edge of a graphical background layer. I have been using the TextGetSize() function to calculate the width of the text and attempting to position the text by subtracting this width from the right edge X-coordinate of the background. However, the results are not accurate, and the text does not align with the right edge as expected.
Here is the code snippet I used:
obj.TextCreate(0, "n 1", 0, CalculateLeftAlignmentX(GetRightEdge(0, "n bitlabel"), "ON", 10), y + y_distance * 1, 10, "Arial", "ON", clrYellow);
obj.TextCreate(0, "n 2", 0, CalculateLeftAlignmentX(GetRightEdge(0, "n bitlabel"), "999", 10), y + y_distance * 2, 10, "Arial", "999", clrYellow);
obj.TextCreate(0, "n 3", 0, CalculateLeftAlignmentX(GetRightEdge(0, "n bitlabel"), "IC MARKETS", 10), y + y_distance * 3, 10, "Arial", "IC MARKETS", clrYellow);
int GetRightEdge(const int chart_ID, const string ref_name)
{
int ref_x = (int)ObjectGetInteger(chart_ID, ref_name, OBJPROP_XDISTANCE) + (int)ObjectGetInteger(chart_ID, ref_name, OBJPROP_XSIZE);
return ref_x;
}
int CalculateLeftAlignmentX(const int rightEdgeX, const string text, const int distance)
{
uint text_width, text_height;
TextGetSize(text, text_width, text_height);
int new_x = rightEdgeX - text_width - distance;
printf("%f",text_width);
return new_x;
}
Does anyone know a more accurate method to measure text width, or are there other techniques that can help achieve this alignment? Thank you for your help!