Help Button

 
Hi guys, I created a button object for a marker (the code is below), when I "press it" It is all right and it executes the part of the code " //Button is pressed ", the problem is when I "resume" that should execute the part of the code " //Button is not pressed " instead it executes only " Print ("hello");" in fact in the "advisors tab" appears "hello", how come, where I went wrong.

This button panel is used to show various things on the chart, one of these is to mark the min and max monthly, now, if I click the button and change TF, the button "remains clicked" but the min/max monthly is deleted on the chart, how should I do to avoid the deletion?

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


  if(id==CHARTEVENT_OBJECT_CLICK){
      //--- If you click on the object with the name buttonID
    if(sparam=="MaxMinAnnu") //Button is pressed
        {
         //--- State of the button - pressed or not
         if(ObjectGetInteger(0,"MaxMinAnnu",OBJPROP_STATE)==true)
           {
            if(barre<Bars)
            {
               barre=Bars;           
               show_max_12MN=true; 
               show_min_12MN=true; 
               drawAll(); 

           }

         else// Button is not pressed
           {
           ObjectDelete(0,"max_1MN");
           Print("ciao");

           }
          }
      ChartRedraw();
      } 
 
Hi Guys, I solved the first problem now it executes both the code of when the button "is pressed" and the code of when the button "is not pressed".
Now the problem is this one:
- when "I press the button" it shows some levels on the graph (I attach figure 2 "button clicked"); 
- I have the problem when "I press the button" and change TF, the button remains pressed but it deletes the levels ( I attach figure 1 "button clicked" to the TF change"; 
- how do I fix it to not delete the levels when changing TF? I also tried to delete the "OnDeinit" function but the problem remains the same.



I have done more than one indicator and I never had this problem, this is the first one where I use the button object and I have this problem doesn't depend on this?

I also did the test clicking with the "right button" - Object List : I press the button in h4 and in Object List: there are the created objects that are printed on the chart, if I change TF they disappear I don't really understand the problem, do you have any suggestions?

 if(sparam=="OpenCloseDay")
        {

         if(PressedOpenCloseD1)//if(ObjectGetInteger(0,"OpenCloseSem",OBJPROP_STATE)==true) //Premuto
           {
            // ObjectSetInteger(0,"OpenCloseSem",OBJPROP_STATE,false);
            if(barre<Bars)
            {
               barre=Bars;           
               show_open_D1=true; 
               show_close_D1=true; 
               drawAll(); 
            }
           }
           else//non premuto
            {  show_open_D1=false; show_close_D1=false; 
               ObjectDelete(0,"open_D1_txt");ObjectDelete(0,"open_D1");ObjectDelete(0,"open_D1_txt");
               ObjectDelete(0,"close_D1_txt");ObjectDelete(0,"close_D1");ObjectDelete(0,"close_D1_txt");
               ObjectSetInteger(0,"MaxMinDay",OBJPROP_STATE,false);       

            }
         PressedOpenCloseD1= !PressedOpenCloseD1;
         } 
Reason: