Download MetaTrader 5

Button code creating mt4 bug.

To add comments, please log in or register
Thierry Ramaniraka
356
Thierry Ramaniraka  

Hello there,
I am creating a  buttons panel, so far is so god, but whent i am trying to aatach zoom function to my zoom buttons,
I get this bug :

The timeframe buttons do not released, and i cannot erase a template, when i want to save it.

Here is my code (What is wrong please ? ) :

long ChartScale=ChartGetInteger(0,CHART_SCALE);
   ChartSetInteger(0,CHART_SCALE,(int)ChartScale);
   bool Button_Zoom_In_State=ObjectGetInteger(0,"Button_Zoom_In",OBJPROP_STATE);
   if(Button_Zoom_In_State == true)
   {
      ObjectSetInteger(0,"Button_Zoom_In",OBJPROP_STATE,false);
                ChartSetInteger(0,CHART_SCALE,(int)ChartScale+1); 
      Comment("Button_Zoom_In pressed");
   }
   
   bool Button_Zoom_Out_State=ObjectGetInteger(0,"Button_Zoom_Out",OBJPROP_STATE);
   if(Button_Zoom_Out_State == true)
   {
      ObjectSetInteger(0,"Button_Zoom_Out",OBJPROP_STATE,false);
                ChartSetInteger(0,CHART_SCALE,(int)ChartScale-1); 
      Comment("Button_Zoom_Out pressed");
   }

Regards.

Marco vd Heijden
Moderator
6522
Marco vd Heijden  

Possibly you are continuously setting the chart scale by this call:

ChartSetInteger(0,CHART_SCALE,(int)ChartScale);

So you can try like this:

long ChartScale=ChartGetInteger(0,CHART_SCALE);
   //ChartSetInteger(0,CHART_SCALE,(int)ChartScale);
   bool Button_Zoom_In_State=ObjectGetInteger(0,"Button_Zoom_In",OBJPROP_STATE);
   if(Button_Zoom_In_State == true)
   {
      ObjectSetInteger(0,"Button_Zoom_In",OBJPROP_STATE,false);
                ChartSetInteger(0,CHART_SCALE,(int)ChartScale+1); 
      Comment("Button_Zoom_In pressed");
   }
   
   bool Button_Zoom_Out_State=ObjectGetInteger(0,"Button_Zoom_Out",OBJPROP_STATE);
   if(Button_Zoom_Out_State == true)
   {
      ObjectSetInteger(0,"Button_Zoom_Out",OBJPROP_STATE,false);
                ChartSetInteger(0,CHART_SCALE,(int)ChartScale-1); 
      Comment("Button_Zoom_Out pressed");
   }

And see if it differs.

Thierry Ramaniraka
356
Thierry Ramaniraka  
Marco vd Heijden:

Possibly you are continuously setting the chart scale by this call:

So you can try like this:

And see if it differs.

Perfect.
Thank you very much. : )

Thierry Ramaniraka
356
Thierry Ramaniraka  
In the same kind of idea,
What is the way to detect the current timeframe please ?

Same thing that chart scale but now, for timeframe ?
whroeder1
17828
whroeder1  
Perhaps you should read the manual.
ChartPeriod Returns the timeframe period of specified chart.
          ChartPeriod - Chart Operations - MQL4 Reference
and for the current chart you can just use _Period or Period()
Thierry Ramaniraka
356
Thierry Ramaniraka  
whroeder1:
Perhaps you should read the manual. and for the current chart you can just use _Period or Period()

Hello,
i tried and tried again, even with enutimframe...with no success.

So i though that an old school beginner's way will do the job ... but no.
If I am on tf M1, when i click on _Button_TimeFrame_Higher  the chart jump directly on the M30 timeframe.

What is wrong please ?

if(Period()==PERIOD_M1 && _Button_TimeFrame_Higher_State == true)
   {
         ObjectSetInteger(0,"_Button_TimeFrame_Higher",OBJPROP_STATE,false);
         ChartSetSymbolPeriod(0,NULL,PERIOD_M5);
   }
   if(Period()==PERIOD_M5 && _Button_TimeFrame_Higher_State == true)
   {
         ObjectSetInteger(0,"_Button_TimeFrame_Higher",OBJPROP_STATE,false);
         ChartSetSymbolPeriod(0,NULL,PERIOD_M15);
   }
   if(Period()==PERIOD_M15 && _Button_TimeFrame_Higher_State)
   {
         ObjectSetInteger(0,"_Button_TimeFrame_Higher",OBJPROP_STATE,false);
         ChartSetSymbolPeriod(0,NULL,PERIOD_M30);
   }
whroeder1
17828
whroeder1  
Thierry Ramaniraka: I am on tf M1, when i click on _Button_TimeFrame_Higher  the chart jump directly on the M30 timeframe.

If M1 change to M5. If M5 (now true) change to M15, If M15 (now true) change to M30. Why do you expect anything else?

Change your code to if ... else if ... else if so you only change once per click.

kypa
777
kypa  
You can also rearrange them 15 to 30 first, then 5 to 15 and 1 to 5 the last, if you dislike thinking too much. If/else is the proper way though, as it can save one or more operations.
Thierry Ramaniraka
356
Thierry Ramaniraka  
kypa:
You can also rearrange them 15 to 30 first, then 5 to 15 and 1 to 5 the last, if you dislike thinking too much. If/else is the proper way though, as it can save one or more operations.

As i want to go forward, I have quickly test your idea...And it works fine.
I probably will do it more academic later.
For now, i do it your way.

Thank you.

To add comments, please log in or register