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.
OBJPROP_BGCOLOR is the background color for "OBJ_EDIT", "OBJ_BUTTON", "OBJ_RECTANGLE_LABEL"
A workaround: create the "OBJ_RECTANGLE_LABEL" object (where you can apply the background colour) first, then the "OBJ_LABEL" object as shown below:
***
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Properties
- www.mql5.com
Object Properties - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
MirellaSquarcia # :
As a matter of fact OBJPROP_BGCOLOR is not available for OBJ_LABEL objects.
OBJPROP_BGCOLOR is the background color for "OBJ_EDIT", "OBJ_BUTTON", "OBJ_RECTANGLE_LABEL"
A workaround: create the "OBJ_RECTANGLE_LABEL" object (where you can apply the background colour) first, then the "OBJ_LABEL" object as shown below:
***
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
Vladimir Karputov #:
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.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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);
}
//+------------------------------------------------------------------+