ChartEvent disables after restart

 

Hello everyone,

I have an EA that has 1 button on it (for convenience instead of changing EA settings). That button shows whether EA is ready to send a trade at some conditions, or will ignore those conditions, and I can press it so changing this status. so ea operated partially manually. Everything is fine, but I noticed a strange situation: if I restart EA (ie recompile or shut down a terminal and restart again) -  then button becomes inactive, and the whole function OnChartEvent doesnt work.

 So after restart I click on objects and on chart or whatsoever do and do not receive a message "92OnChartEvent ..." in the logs. For some reason OnChartEvent fn is completely ignored. Could you plese help? Thanks in advance

void OnChartEvent(const int id,const long& lparam,const double& dparam,const string& sparam){
   Print(92,__FUNCTION__," ",id," ",EnumToString((ENUM_CHART_EVENT)id)," ",sparam,"?=",button_name);
   if(id==CHARTEVENT_OBJECT_CLICK){
      if(sparam==button_name){
         bool selected=ObjectGetInteger(0,button_name,OBJPROP_STATE);
         Print("Button pressed = ",(selected?"break":"working")," at ",TimeToStr(
            TimeCurrent(),TIME_DATE|TIME_MINUTES|TIME_SECONDS));
         if(selected){//--- If the button is pressed
            ObjectSetString(0,button_name,OBJPROP_TEXT,string_break);
            ObjectSetInteger(0,button_name,OBJPROP_COLOR,clr_stop);
            button_state = selected;
         }else{ // Button is not pressed
            ObjectSetString(0,button_name,OBJPROP_TEXT,string_work);
            ObjectSetInteger(0,button_name,OBJPROP_COLOR,clr_working);
            button_state = selected;
         }
      }
      ChartRedraw();// Forced redraw all chart objects
   }
}
 
danik:

Hello everyone,

I have an EA that has 1 button on it (for convenience instead of changing EA settings). That button shows whether EA is ready to send a trade at some conditions, or will ignore those conditions, and I can press it so changing this status. so ea operated partially manually. Everything is fine, but I noticed a strange situation: if I restart EA (ie recompile or shut down a terminal and restart again) -  then button becomes inactive, and the whole function OnChartEvent doesnt work.

 So after restart I click on objects and on chart or whatsoever do and do not receive a message "92OnChartEvent ..." in the logs. For some reason OnChartEvent fn is completely ignored. Could you plese help? Thanks in advance

 

 

 

ok, problem sovled. I had constant button name, changed to 

string buttone_name;

OnInit(){button_name = "Button";  ... } and now seems it works