Non-deterministic Behavior with CChartObjectButton.State() method - bug??

 

To Development team of MQL5,

I don't understand why the hell the State() method shows non-deterministic behavior when I use it to check if a CChartObjectButton is "pressed" or not!


Wenn I press both buttons and move both lines, it looks like this:



When I wait some time and do nothing it looks like this:



What's wrong?? Thanks...


Here is my code:


//+------------------------------------------------------------------+
//|                                                   SmartOrder.mq5 |
//|                        Copyright 2010, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"

#include <ChartObjects\ChartObjectsLines.mqh>
#include <ChartObjects\ChartObjectsTxtControls.mqh>


class PlaceStopAndProfitCtrl
{
   protected:
   
      CChartObjectButton      m_button_placeStop;
      CChartObjectButton      m_button_placeTakeProfit;
      
      
   public:
                           PlaceStopAndProfitCtrl();
      bool                 Init();
      void                 Deinit();
      void                 Processing();
      
   private:
      void                 checkButtons();
        
      bool                 stopLine;
      bool                 takeProfitLine;
      
      double               closePrice[];
      
};

PlaceStopAndProfitCtrl             ExtScript;

PlaceStopAndProfitCtrl::PlaceStopAndProfitCtrl()
{
   Print("Starting PlaceStopAndProfit...");
}

bool PlaceStopAndProfitCtrl::Init()
{
   Print("INIT...");

   stopLine = false;
   takeProfitLine = false;
   
   int button_width = 80;
   int button_height = 20;


   int sx = 20;
   int sy = 20;
   
   int offset_label_x = 20;
   
   color color_label = WhiteSmoke;

   m_button_placeStop.Create(0,"ButtonPlaceStop",0,sx,sy+70,button_width,button_height);
   m_button_placeStop.Description("Stop");
   m_button_placeStop.Color(Red);
   m_button_placeStop.FontSize(8);
   
   m_button_placeTakeProfit.Create(0,"ButtonPlaceTakeProfit",0,sx+button_width+4,sy+70,button_width,button_height);
   m_button_placeTakeProfit.Description("TakeProfit");
   m_button_placeTakeProfit.Color(Green);
   m_button_placeTakeProfit.FontSize(8);
 
   return(0);
}

void PlaceStopAndProfitCtrl::checkButtons()
{
   if(ArraySize(closePrice) == 0) {  
      CopyClose(Symbol(),PERIOD_D1,0,1,closePrice);
   } 
   
   else if(m_button_placeStop.State() && !stopLine) {
      Print("CREATE COMMAND: STOPLOSS LINE");
      ObjectCreate(0,"StopLine",OBJ_HLINE,0,NULL,closePrice[0]);
      ObjectSetInteger(0,"StopLine",OBJPROP_COLOR,DeepPink);
      ObjectSetInteger(0,"StopLine",OBJPROP_STYLE,STYLE_DASH);
      ObjectSetInteger(0,"StopLine",OBJPROP_SELECTABLE,true);
      stopLine = true;
   }
   else if(!m_button_placeStop.State() && stopLine) {
      Print("DELETE COMMAND: STOPLOSS LINE");
      ObjectDelete(0,"StopLine");
      Print("STOPLOSS LINE DELETED...");
      stopLine = false;
   }
   else if(m_button_placeTakeProfit.State() && !takeProfitLine) {
      Print("CREATE COMMAND: TAKE PROFIT LINE");
      ObjectCreate(0,"TakeProfitLine",OBJ_HLINE,0,NULL,closePrice[0]);
      ObjectSetInteger(0,"TakeProfitLine",OBJPROP_COLOR,Green);
      ObjectSetInteger(0,"TakeProfitLine",OBJPROP_STYLE,STYLE_DASH);
      ObjectSetInteger(0,"TakeProfitLine",OBJPROP_SELECTABLE,true);
      takeProfitLine = true;
   }
   else if(!m_button_placeTakeProfit.State() && takeProfitLine) {
      Print("DELETE COMMAND: TAKE PROFIT LINE");
      ObjectDelete(0,"TakeProfitLine");
      Print("TAKE PROFIT LINE DELETED...");
      takeProfitLine = false;
   }
}

void PlaceStopAndProfitCtrl::Processing()
{
   checkButtons();
   ChartRedraw();
   Sleep(150);
}


void PlaceStopAndProfitCtrl::Deinit()
{
   Print("DEINIT..");
}

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
int OnStart()
  {
//---
   //--- call init function
   if(ExtScript.Init()==0)
     {
      //--- cycle until the script is not halted
      while(!IsStopped()) ExtScript.Processing();
     }
//--- call deinit function
   ExtScript.Deinit();
//---
   return(0);
  }
//+------------------------------------------------------------------+
 
Thank for your message. Bug fixed.
Reason: