color OBJ_LABEL_BackgrColor=clrLightSkyBlue; int XAnchor=10; int YAnchor=30; int Width=140; int Height=30; int XObjectWidthInPixels=80; int YObjectWidthInPixels=20; string objectName; objectName="Rectangle My Label"; ObjectCreate(0,objectName,OBJ_RECTANGLE_LABEL,0,0,0); ObjectSetInteger(0,objectName,OBJPROP_XDISTANCE,XAnchor); ObjectSetInteger(0,objectName,OBJPROP_YDISTANCE,YAnchor); ObjectSetInteger(0,objectName,OBJPROP_XSIZE,Width); ObjectSetInteger(0,objectName,OBJPROP_YSIZE,Height); ObjectSetInteger(0,objectName,OBJPROP_BGCOLOR,OBJ_LABEL_BackgrColor); objectName="OBJ_LABEL My Label"; ObjectCreate(0,objectName,OBJ_LABEL,0,0,0); ObjectSetInteger(0,objectName,OBJPROP_XDISTANCE,XAnchor); ObjectSetInteger(0,objectName,OBJPROP_YDISTANCE,YAnchor); ObjectSetString(0,objectName,OBJPROP_TEXT,"My Label bla bla bla..."); ObjectSetInteger(0,objectName,OBJPROP_COLOR,clrBlack);As a matter of fact OBJPROP_BGCOLOR is not available for OBJ_LABEL objects.
***

- www.mql5.com
***
1. Before writing, did you look at the date of the last message? You raised the dead :)
2. Please insert the code correctly: when editing a message, press the button and paste your code into the pop-up window
1. Before writing, did you look at the date of the last message? You raised the dead :)
2. Please insert the code correctly: when editing a message, press the button and paste your code into the pop-up window
Thank you. Indeed this is an old message though since the post is still active this may be searched for by other users.
I now entered the code correctly and thanks again for letting me know how to post code properly.
This looks like still as an open issue, since OBJ_LABEL takes the the width of the contained text, while OBJ_RECTANGLE needs a specific width to be set, so you can match the width of the background only for static text. If you have a label with variable text (e.g. symbol description) it's not possible to set a correct background color.
OBJ_LABEL
I believe OBJPROP_BGCOLOR should apply also to OBJ_LABEL, this would be the most logical and expected way.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
This code never seems to apply a background color to my text OBJ_LABEL. The background is always clear. Am I missing something?
Thanks.
//| test.mq5 |
//| Copyright 2016, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
string labelID5 = "HeaderLabel5";
int OnInit()
{
ObjectDelete(0,"HeaderLabel5");
ObjectCreate(0,labelID5,OBJ_LABEL,0,100,100);
ObjectSetInteger(0,labelID5,OBJPROP_BGCOLOR,clrAliceBlue);
ObjectSetInteger(0,labelID5,OBJPROP_COLOR,clrBlack);
ObjectSetInteger(0,labelID5,OBJPROP_XDISTANCE,0);
ObjectSetInteger(0,labelID5,OBJPROP_YDISTANCE,100);
ObjectSetString(0,labelID5,OBJPROP_FONT,"Trebuchet MS");
ObjectSetInteger(0,labelID5,OBJPROP_FONTSIZE,10);
ObjectSetInteger(0,labelID5,OBJPROP_SELECTABLE,0);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
ObjectSetString(0,labelID5,OBJPROP_TEXT, "TEST2");
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+