Issue: the color C'34,34,34' (and similar dark colors within that range) display differently on OBJ_BUTTON compared to other object types.
In the video, the OBJ_EDIT is also using C'34,34,34' as the background color that the OBJ_BUTTON uses in the on state. However, they don't look the same.
I left a note in the code below stating that, if you comment out the line that changes the color in the off state, the color displays properly, but not in the correct state.
Code below to test for yourself.
#property strict#property indicator_chart_window//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit() {
createButton();
createEdit();
return(INIT_SUCCEEDED);
}
void createButton() {
string name = "TEST BUTTON";
color clr = clrWhite;
color bgClr = clrBlack;
int x = 100;
int y = 5;
int width = 200;
int height = 100;
bool wasCreated = ObjectCreate(0, name, OBJ_BUTTON, 0, 0, 0);
if (wasCreated) {
ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
ObjectSetInteger(0, name, OBJPROP_BGCOLOR, bgClr);
ObjectSetInteger(0, name, OBJPROP_XSIZE, width);
ObjectSetInteger(0, name, OBJPROP_YSIZE, height);
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x);
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y);
}
}
void createEdit() {
string name = "TEST EDIT";
color clr = clrWhite;
color bgClr = C'34,34,34';
int x = 100;
int y = 100 + 5 + 5;
int width = 200;
int height = 100;
bool wasCreated = ObjectCreate(0, name, OBJ_EDIT, 0, 0, 0);
if (wasCreated) {
ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
ObjectSetInteger(0, name, OBJPROP_BGCOLOR, bgClr);
ObjectSetInteger(0, name, OBJPROP_XSIZE, width);
ObjectSetInteger(0, name, OBJPROP_YSIZE, height);
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x);
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y);
}
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[]) {
return(rates_total);
}
//+------------------------------------------------------------------+//| ChartEvent function |//+------------------------------------------------------------------+voidOnChartEvent(constint id,
constlong &lparam,
constdouble &dparam,
conststring &sparam) {
switch (id) {
caseCHARTEVENT_OBJECT_CLICK: {
bool isButton = sparam == "TEST BUTTON";
if (isButton) {
bool isState = ObjectGetInteger(0, sparam, OBJPROP_STATE);
if (isState) {
color bgClr = C'34,34,34';
string message = StringConcatenate("State: ", isState, "\n", "Color: ", bgClr);
Comment(message);
ObjectSetInteger(0, sparam, OBJPROP_BGCOLOR, bgClr);
} else {
color bgClr = clrBlack;
string message = StringConcatenate("State: ", isState, "\n", "Color: ", bgClr);
Comment(message);
//--- NOTE: If you comment out this line, the color displays properly, but only when//--- the button state is false, rather than true (when the color is supposed to be applied)ObjectSetInteger(0, sparam, OBJPROP_BGCOLOR, bgClr);
}
}
break;
}
}
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Video demonstration: https://i.imgur.com/ee1JSo8.gif
Issue: the color C'34,34,34' (and similar dark colors within that range) display differently on OBJ_BUTTON compared to other object types.
In the video, the OBJ_EDIT is also using C'34,34,34' as the background color that the OBJ_BUTTON uses in the on state. However, they don't look the same.
I left a note in the code below stating that, if you comment out the line that changes the color in the off state, the color displays properly, but not in the correct state.
Code below to test for yourself.