You need to add a command to specify the location of the text.
Add these two lines
ObjectSetInteger(0,price_level,OBJPROP_YDISTANCE,3); // ( current chart, name of object, y or x distance from upper left corner, distance in pixals) ObjectSetInteger(0,price_level,OBJPROP_XDISTANCE,100);
Change the value 3 to move up or down
Change the value 100 to move left or right
you can use chat GPT for some questions : it cant yet be compared with some of the best coders here but for someone learning it can give you some ideas as what to look for dumb question would result in dumb answer :
Based on the code provided, it seems like you're creating a text object on the chart and positioning it based on the bid price of the symbol. However, you mentioned that the text appears at a certain distance that is changing over time. This could be due to the following reasons:
-
The value of " price_lev" is changing over time: In the code you provided, " price_lev" is calculated as price+0.45 . If the value of price is changing over time, then the value of " price_lev" will also change. This could be causing the text object to appear at a different distance from the bid line over time.
-
The position of the text object is relative to the chart: In the code you provided, the position of the text object is set as close[0] . If the value of close[0] is changing over time, then the position of the text object will also change. This could be causing the text object to appear at a different distance from the bid line over time.
To fix the issue, you can try the following:
-
Use a fixed value for " price_lev" : Instead of calculating " price_lev" as price+0.45 , you can use a fixed value for " price_lev" , such as price+0.00045 . This will ensure that the position of the text object remains fixed relative to the bid line.
-
Use a fixed position for the text object: Instead of setting the position of the text object as close[0] , you can set it to a fixed value, such as Bid-0.0001 . This will ensure that the position of the text object remains fixed relative to the bid line.
Here's an updated version of your code that implements these changes:
price = DoubleToString(SymbolInfoDouble(_Symbol, SYMBOL_BID), _Digits); price_lev = DoubleToString(SymbolInfoDouble(_Symbol, SYMBOL_BID) + 0.00045, _Digits); price_level_line = "Bid + 0.00045"; ObjectCreate(0, price_level, OBJ_TEXT, 0, 0, 0); ObjectSetDouble(0, price_level, OBJPROP_PRICE, SymbolInfoDouble(_Symbol, SYMBOL_BID) - 0.0001); ObjectSetInteger(0, price_level, OBJPROP_COLOR, clrWhite); ObjectSetString(0, price_level, OBJPROP_TEXT, price_level_line); ObjectSetInteger(0, price_level, OBJPROP_FONTSIZE, fontSize); ObjectSetString(0, price_level, OBJPROP_FONT, "Tahoma");
In this version of the code, " price_lev" is no longer used, and the position of the text object is set to Bid-0.0001 , which should be a fixed distance from the bid line.
The answer for Christopher Hubert Gainsford.
Thanks for your work. The text in price_level_line is in fact a white line "_______________".
The problem is I cannot remove the price_lev variable because at a certain point I want to pass that value to a shorter line "____" tha will appear fixed on the chart representing a resistance or a support level based on some other calculations.
The white line then will continue to appear at bid price level while the old value would produce a fixed red or green line.
I used the code you provided to calculate the price_lev variable "price_lev=DoubleToString(SymbolInfoDouble(_Symbol, SYMBOL_BID) - 0.0001);" that also worked in mantaining the line at a fixed distance from the bid line.
But for graphic reasons the underscore text line needs some adjustment to appear at the right distance from the bid line that's why I wanted to add 0.45 to the bid value.
At this point there's some sort of mistery I'm not able to solve. Why "price_lev=DoubleToString(SymbolInfoDouble(_Symbol, SYMBOL_BID) - 0.0001);" alone is working in mantaining a fixed distance from the bid line while if I add
"price_lev=(price_lev + 0.45);" and pass this value to the code the distance from the bid line will not constant. It is like the 0.45 value is not interpreted as a fixed number of points added to the price but it could be 0.25 or 0.76 depending on a scale.
ObjectCreate(0, price_level, OBJ_TEXT, 0, 0, 0);into the code but this way the line even disappear.
I also tried to integrate the code " into the code but this way the line even disappear.
Here you can find plenty of working examples: https://www.mql5.com/en/search#!keyword=obj_text.
Filter for articles if you want detailed explanation or CodeBase on the left side.
Please, be comprehensive, it's impossible to find this information in the examples.
The answer I'm asking is simply why
price_lev=DoubleToString(SymbolInfoDouble(_Symbol, SYMBOL_BID) - 0.0001);
will produce an object that remains at a constant distance from the bid line while
price_lev=DoubleToString(SymbolInfoDouble(_Symbol, SYMBOL_BID) - 0.0001); price_lev=(price_lev + 0.45);will not. Is it some bug?
Please, be comprehensive, it's impossible to find this information in the examples.
The answer I'm asking is simply why
will produce an object that remains at a constant distance from the bid line while
Is price_lev a string ? Unlike javascript mql5 does not automatically cast variables

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi. I'm trying to position a string of text on the bid line but the text appears at a certain distance that is also changin over time. Can someone explain wich is the problem? This is the code
price=DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
price_lev=(price+0.45);
ObjectCreate(0,price_level,OBJ_TEXT,0,time[0]+PeriodSeconds()*2,close[0]);
ObjectSetDouble(0, price_level, OBJPROP_PRICE, price_lev);
ObjectSetDouble(0, price_level, OBJPROP_PRICE, price_lev);
ObjectSetInteger(0,price_level,OBJPROP_COLOR,clrWhite);
ObjectSetString(0,price_level,OBJPROP_TEXT,price_level_line);
ObjectSetInteger(0,price_level,OBJPROP_FONTSIZE,fontSize);
ObjectSetString(0,price_level,OBJPROP_FONT,"Tahoma");