Buttons cancel each other out

Back to topics list To post a new topic, please log in or register
avatar
21
Roddo 2016.09.20 03:06
 

I have assembled a Chart Zoom Out Button for "CHART_SCALE"  works just fine until I add the opposite condition Zoom In then they cancel each other out.

Could someone show or explain what I need to do to have them both in the same Indicator.

I have attached the both working Indicators so you can see what I have done.

Thank you

Rod 

 

 

Attached files:
  zoomout_button_1.mq4  (7.13 KB)
avatar
21
Roddo 2016.09.20 03:07 #
 
button 2
Attached files:
  zoomin_button.mq4  (7.15 KB)
avatar
13006
WHRoeder 2016.09.20 15:33 #
 
Roddo: I have attached the both working Indicators so you can see what I have done.
What we need to see is the code that doesn't work.

avatar
21
Roddo 2016.09.20 17:10 #
 
WHRoeder:
Roddo: I have attached the both working Indicators so you can see what I have done.
What we need to see is the code that doesn't work.

Hi WHRoeder,

Thanks for the reply.

the Indicators both work separately. It is when they are both on the chart at the same time is when neither work.

I actually had them in the same indicator to start with but they seemed to cancel each other out.

At the moment I am using just one button and ending the loop with a 5 and sending it back to 0 .

Thank you for your interest

Roddo 

 

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//+------------------------------------------------------------------+
//|   ZoomIN   sparam                                                            |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|      ZoomIN   sparam                                                            |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|      ZoomOUT   sparam                                                            |
//+------------------------------------------------------------------+

   if(id==CHARTEVENT_OBJECT_CLICK)
     {
      if(sparam==Zout_Button) Zout_Toggle();
        {
        if(ChartGetInteger(0,CHART_SCALE,0,result))
           {
            if(result==5)
              {
               ChartSetInteger(0,CHART_SCALE,0,4);//Comment
               Print("Chart Scale = "+(string)result);
              }
            else if(result==4)
              {
               ChartSetInteger(0,CHART_SCALE,0,3);
               Print("Chart Scale = "+(string)result);
              }
            else if(result==3)
              {
               ChartSetInteger(0,CHART_SCALE,0,2);
               Print("Chart Scale = "+(string)result);
              }
            else if(result==2)
              {
               ChartSetInteger(0,CHART_SCALE,0,1);
               Print("Chart Scale = "+(string)result);
              }
            else if(result==1)
              {
               ChartSetInteger(0,CHART_SCALE,0,0);
               Print("Chart Scale = "+(string)result);
              }
           }
        }
     }

  }
//+------------------------------------------------------------------+
//|      ZoomOUT   sparam                                                            |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//+------------------------------------------------------------------+
//|   ZoomIN   sparam                                                            |
//+------------------------------------------------------------------+
   if(id==CHARTEVENT_OBJECT_CLICK)
     {
      if(sparam==Zin_Button) Zin_Toggle();
        {
         if(ChartGetInteger(0,CHART_SCALE,0,result))
           {
            if(result==0)
              {
               ChartSetInteger(0,CHART_SCALE,0,1);//Comment
               Print("Chart Scale = "+(string)result);
              }
            else if(result==1)
              {
               ChartSetInteger(0,CHART_SCALE,0,2);
               Print("Chart Scale = "+(string)result);
              }
            else if(result==2)
              {
               ChartSetInteger(0,CHART_SCALE,0,3);
               Print("Chart Scale = "+(string)result);
              }
            else if(result==3)
              {
               ChartSetInteger(0,CHART_SCALE,0,4);
               Print("Chart Scale = "+(string)result);
              }
            else if(result==4)
              {
               ChartSetInteger(0,CHART_SCALE,0,5);
               Print("Chart Scale = "+(string)result);
              }
           }
        }
     }
//+------------------------------------------------------------------+
//|      ZoomIN   sparam                                                            |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|      ZoomOUT   sparam                                                            |
//+------------------------------------------------------------------+


  }
//+------------------------------------------------------------------+
//|      ZoomOUT   sparam                                                            |
//+------------------------------------------------------------------+
avatar
13006
WHRoeder 2016.09.20 18:45 #
 
  1.    if(id==CHARTEVENT_OBJECT_CLICK)
         {
          if(sparam==Zin_Button) Zin_Toggle();
            {
             if(ChartGetInteger(0,CHART_SCALE,0,result))
    I missed the problem the first time. If you click on the Zout_Buttton, it calls Zout_Toggle, and then (for click on any object) it changes the scale. Fix your braces.

  2. For counting up, simplify
     Your code
    if(ChartGetInteger(0,CHART_SCALE,0,result)){
       result = (result + 1) % 6; // 0, 1, 2, 3, 4, 5, 0...
       ChartSetInteger(0,CHART_SCALE,0,result);
       Print("Chart Scale = "+(string)result);
    }
    
    if(ChartGetInteger(0,CHART_SCALE,0,result))
               {
                if(result==0)
                  {
                   ChartSetInteger(0,CHART_SCALE,0,1);//Comment
                   Print("Chart Scale = "+(string)result);
                  }
                else if(result==1)
                :
    
  3. For counting down, simplify
    Your code
    if(ChartGetInteger(0,CHART_SCALE,0,result)){
       result =  (result + 5) % 6; // 5, 4, 3, 2, 1, 0, 5...
       ChartSetInteger(0,CHART_SCALE,0,4);
       Print("Chart Scale = "+(string)result);
    }
    
    if(ChartGetInteger(0,CHART_SCALE,0,result))
               {
                if(result==5)
                  {
                   ChartSetInteger(0,CHART_SCALE,0,4);//Comment
                   Print("Chart Scale = "+(string)result);
                  }
                else if(result==4)
                :
    

  4. Simply
    Your code
    Print("Chart Scale = ", result);
    //or
    PrintFormat("Chart Scale = %i", result);
    Print("Chart Scale = "+(string)result);

avatar
21
Roddo 2016.09.21 03:20 #
 
WHRoeder:
  1. I missed the problem the first time. If you click on the Zout_Buttton, it calls Zout_Toggle, and then (for click on any object) it changes the scale. Fix your braces.

  2. For counting up, simplify
     Your code
  3. For counting down, simplify
    Your code

  4. Simply
    Your code

Hi WHRoeder,

I have added your code but I still get the same problem. No Worries my head at the moment is like a brick.

BTW did you get a chance to load these buttons onto a chart together.

I will keep pocking a stick at it until I get a reaction I like.

 

Cheers and Thanks

Roddo 

Back to topics list  

To add comments, please log in or register