Write some text on the top or bottom of the candle

 

I'm trying to write some text on the top or bottom of the candle (closest possible). I'm using the code below without success:

void DrawText(string text,const double &high[],const datetime &time[])
{
 
    //datetime Time = TimeCurrent(); // Get the current time
    double price = high[0]; // Get the price of the current candle
    int font_size = 10;
    color font_color = clrRed;
   
   
    // Convert datetime to screen x coordinate
    int x_coordinate, y_coordinate; 
    ChartTimePriceToXY(0,0,time[0],price,x_coordinate,y_coordinate); 
 
    // Draw the text
    ObjectCreate(0, "CandleText", OBJ_TEXT, 0, 0, 0); 
    ObjectSetInteger(0,"CandleText",OBJPROP_XDISTANCE,x_coordinate);
    ObjectSetInteger(0,"CandleText",OBJPROP_YDISTANCE,y_coordinate);
    ObjectSetString(0, "CandleText", OBJPROP_TEXT, text);
    ObjectSetString(0, "CandleText", OBJPROP_FONT, "Arial");
    ObjectSetInteger(0, "CandleText", OBJPROP_FONTSIZE, font_size);
    ObjectSetInteger(0, "CandleText", OBJPROP_COLOR, font_color);
} 

Please, can anybody point me to what I'm doing wrong.

Thanks.

 
Look up "OBJ_TEXT", in the reference guide, all the examples/help you need is there.
 

OBJ_TEXT is anchored in time and price not xy coordinates. Check documentation. There is an example in there.

https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_text

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_TEXT
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_TEXT
  • www.mql5.com
Text object. Note Anchor point position relative to the text can be selected from ENUM_ANCHOR_POINT enumeration. You can also change text slope...