CChartObjectButton State() mismatch

 

I created a Dialog and added a number of (CButton) buttons to it. Each time I click a button everything seems to work as expected without fail...or was I just lucky?

I then replaced the dialog/CButton's with buttons created by the CChartObjectButton OOP class. 9/10 times it seems to work, but occasionally the button appears as though it was not clicked and the button State() confirms this.

Every time I click a button I can see that the event (CHARTEVENT_OBJECT_CLICK) is being processed, so I know that part is working as expected, but when I check the buttons state, it confirms the buttons visual state that the button was NOT clicked!

I have done a quick search, but cannot find if this is a known issue?

As a test, I wrote the following sample EA which highlights the issue.

#include <ChartObjects/ChartObjectsTxtControls.mqh>
CChartObjectButton button[];
int count = 0;

int OnInit()
{
    count = ArrayResize(button, 10);
    int xPos = 100;
    for (int index = 0; index < count; index++)
    {
        string name = StringFormat("Btn %d", index);
        button[index].Create(0, name, 0, xPos, 100, 100, 30);
        button[index].Description(name);
                
        xPos += 100;
    }
        
    return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason) { }

void OnTick() { }

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{

    if (id == CHARTEVENT_OBJECT_CLICK)
    {
        for (int index = 0; index < count; index++)
        {
            string name = button[index].Name();
            if (sparam == name)
            {
                string state = button[index].State() ? "true" : "false";
                Print(name, " : ", state);
                                
                ChartRedraw();
                break;
            }
        }
    }
}
//+------------------------------------------------------------------+

Does anyone know if this is a known issue and if so, does anyone know if it should work as expected if coded from the ground up using ObjectCreate?

Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Types of Chart Events
Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Types of Chart Events
  • www.mql5.com
There are 11 types of events that can be processed using the predefined function OnChartEvent() . For custom events 65535 identifiers are provided...