Placing text on a chart

 

I use the following code to place text on a chart. In this case, just above the high of a bar by 10 pips (LabelOffset).

            ObjectCreate(StringConcatenate("SS_", Time[i]), OBJ_TEXT, 0, Time[i], High[i] + LabelOffset);
            ObjectSetText(StringConcatenate("SS_", Time[i]), "H", 12, "Times New Roman",Green);

This placement looks fine for some parts of the chart. That is; the text is easy to read. On other parts of the chart the text is further away from the bar high, and in other parts the text overlaps the bar. This is because the bar volatility changes over the chart. 

I would appreciate any suggestions on how to better position the text on the chart.



Thanks,

Mervyn

 
52002651:

Please edit your post and

use the code button (Alt+S) when pasting code

I know that it is not obvious, but topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I will move your topic to the MQL4 and Metatrader 4 section.

 
When placing text using the high of the current bar, you should reset the price co-ordinate until the bar closes.
 

Keith Watford

When placing text using the high of the current bar, you should reset the price co-ordinate until the bar closes.

Thanks for the advice.

However, I see this problem using historic price data. That is; with a fixed level for the high.

 

May I suggest that you try

            string obName=""; //add name
            ObjectSetInteger(0,obName,OBJPROP_ANCHOR,ANCHOR_LOWER); //For objects at the high
            ObjectSetInteger(0,obName,OBJPROP_ANCHOR,ANCHOR_UPPER); //For objects at the low
 

That works very nicely.  


Thank you,

Mervyn

Reason: