Positioning text on chart

 

HI,

I have a horizontal line on my chart which is manually positioned. I would like to position a text label next to it in an EA.

So far I've tried --

double ypos = ObjectGet("Horizontal Line 35541", OBJPROP_PRICE1); and double ypos = ObjectGet("Horizontal Line 35541", OBJPROP_YDISTANCE);

along with ObjectSet("ObjName", OBJPROP_YDISTANCE, ypos); however neither gives me a ypos adjacent to the horizontal line.

I'm totally new to MQL4 so I'm kind of fishing in the dark here. Can anyone help me with a solution to this ?

Thanks.

 

hi


maybe it wont be direct solution for your problem, but in my opinion in most of the situations it is enough to set description to such line and tick "Show object description" option in chart properties.


regards

 
redart:

HI,

I have a horizontal line on my chart which is manually positioned. I would like to position a text label next to it in an EA.

So far I've tried --

double ypos = ObjectGet("Horizontal Line 35541", OBJPROP_PRICE1); and double ypos = ObjectGet("Horizontal Line 35541", OBJPROP_YDISTANCE);

along with ObjectSet("ObjName", OBJPROP_YDISTANCE, ypos); however neither gives me a ypos adjacent to the horizontal line.

I'm totally new to MQL4 so I'm kind of fishing in the dark here. Can anyone help me with a solution to this ?

Thanks.

This is correct . . .

double ypos = ObjectGet("Horizontal Line 35541", OBJPROP_PRICE1);

and it gives a price not a coordinate measured in pixels. Not may Objects can be positioned by pixel coordinate, e.g. labels. It is possible to convert a price to a pixel value but you need to know the size of the window in pixels and then you can scale the Price value to a pixel value . . after you have done all this if you place your Label by a pixel coordinate it will stay in the same position, as more bars arrive on the chart the label will drift away from your line . . .

Instead use Text or a Price Label

 
oromek:

hi


maybe it wont be direct solution for your problem, but in my opinion in most of the situations it is enough to set description to such line and tick "Show object description" option in chart properties.


regards


Thanks for the reply oromek. Your suggestion would give me a label next to the line, but the reason for doing it via EA is so that I have an on-screen confirmation of the EA being launched at the right price.... "If the label is there, then the EA must be there".

Must be some way of setting the position of a text label based on price ?.

 
RaptorUK:

This is correct . . .

and it gives a price not a coordinate measured in pixels. Not may Objects can be positioned by pixel coordinate, e.g. labels. It is possible to convert a price to a pixel value but you need to know the size of the window in pixels and then you can scale the Price value to a pixel value . . after you have done all this if you place your Label by a pixel coordinate it will stay in the same position, as more bars arrive on the chart the label will drift away from your line . . .

Instead use Text or a Price Label


Thanks RaptorUK - knew there had to be an easier way to do this. Got the label next to the line using TEXT -- ObjectCreate("orangelabel", OBJ_TEXT, 0, Time[0], price);. Is there a way to get it positioned next to the price axis rather than in line with the last bar ?
 
redart:

Thanks RaptorUK - knew there had to be an easier way to do this. Got the label next to the line using TEXT -- ObjectCreate("orangelabel", OBJ_TEXT, 0, Time[0], price);. Is there a way to get it positioned next to the price axis rather than in line with the last bar ?
You need to add some "time" to it's time[0] value to compensate for the Chart Shift, the problem that you will face is that it will probably go a little wrong approaching the weekend.
 
RaptorUK:
You need to add some "time" to it's time[0] value to compensate for the Chart Shift, the problem that you will face is that it will probably go a little wrong approaching the weekend.

Thanks again. I got it to work using the "StrToTime" function, but in the end decided to subtract time rather than add it, positioning the label behind the action rather than in front of it.
Reason: