Take a standard example ( CButton ) and add this code for button #1:
//+------------------------------------------------------------------+ //| Event handler | //+------------------------------------------------------------------+ void CControlsDialog::OnClickButton1(void) { Comment(__FUNCTION__); static bool reverse=false; reverse=!reverse; if(reverse) { m_button1.ColorBackground(clrBlue); } else { m_button1.ColorBackground(clrRed); } }
Result:

- www.mql5.com
Thank you very much for the help but I think the information is in mql5 and what I need must be Mql4, I do not know if it is compatible or not. On the other hand I think I have explained myself wrong, I do not need that when pressing the button it changes color, I use the buttons as information windows that give me the current profit or losses and that also change color depending on whether it is in profit , losses or to "0". Can you help me? The code that I have posted sometimes works and the majority is always in GRAY color, the other problem is the decimals of the Profit or loss, I need the profit or loss to be in this format "25.35" but I continually get this format "23.3499999999" and I can't figure out how to remove those annoying "99999999".
Greetings and a thousand thanks in advance.
Hello Vladimir Karputov!
Thank you very much for the help but I think the information is in mql5 and what I need must be Mql4, I do not know if it is compatible or not. On the other hand I think I have explained myself wrong, I do not need that when pressing the button it changes color, I use the buttons as information windows that give me the current profit or losses and that also change color depending on whether it is in profit , losses or to "0". Can you help me? The code that I have posted sometimes works and the majority is always in GRAY color, the other problem is the decimals of the Profit or loss, I need the profit or loss to be in this format "25.35" but I continually get this format "23.3499999999" and I can't figure out how to remove those annoying "99999999".
Greetings and a thousand thanks in advance.
You are on the MQL5 forum. You get all the answers about MQL5.
If you have been using the old terminal until now, please do not waste our time, write strictly in one section of the forum: MQL4 and MetaTrader 4
I'll move your topic.
Floating-point has an infinite number of decimals, it's you, not understanding floating-point and that some numbers can't be represented exactly. (like 1/10.s)
Double-precision floating-point format - Wikipedia
See also The == operand. - MQL4 programming forum 2013.06.07
If you want to see the correct number of digits, convert it to a string with the correct/wanted accuracy.
question about decima of marketinfo() - MQL4 programming forum 2016.05.18

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi! I need help. I have made these buttons with the intention of informing me of the current benefits as well as that they change color depending on whether the benefit is "0" with gains or losses (gray, green or red) and with only two decimal places. In principle it works for me but it does not change color and the decimals of two become 9 or 10. Can someone correct the code so that it works? Thank you very much in advance.