Placing text on a chart

Mervyn Guest
253
Mervyn Guest  

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

Keith Watford
Moderator
28964
Keith Watford  
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.

Keith Watford
Moderator
28964
Keith Watford  
When placing text using the high of the current bar, you should reset the price co-ordinate until the bar closes.
Mervyn Guest
253
Mervyn Guest  

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.

Keith Watford
Moderator
28964
Keith Watford  

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
Mervyn Guest
253
Mervyn Guest  

That works very nicely.  


Thank you,

Mervyn