Which code replicates the double-click over the Y axis in fix-scale mode?

 

Hi,

I'd like to reproduce as code the following steps:

  1. Scale to max zoom out
  2. Increase the value of the min and maximum Y axis (so, if it's plotting $10 - $20, the scales will be like $5 - $25).
  3. Set scales to fix mode
  4. Scale to "normal", original zoom
  5. Double-click over the Y axis
The result will be an axis bar like this:


I already know how to do most of those steps; only the 5th item, the double-click, I don't know how to do it by code. I thought it would be using CHART_PRICE_MAX and CHART_PRICE_MIN, but those seems to be read-only values. So, how can I do this double-click by code? I couldn't find any suitable canditate in all the variables regarding ChartSetDouble (or ChartSetInteger).


 

This should get you started:

//+------------------------------------------------------------------+
//| Gets chart scale (from 0 to 5)                                   |
//+------------------------------------------------------------------+
int ChartScaleGet(const long chart_ID=0)
  {
//--- prepare the variable to get the property value
   long result=-1;
//--- reset the error value
   ResetLastError();
//--- receive the property value
   if(!ChartGetInteger(chart_ID,CHART_SCALE,0,result))
     {
      //--- display the error message in Experts journal
      Print(__FUNCTION__+", Error Code = ",GetLastError());
     }
//--- return the value of the chart property
   return((int)result);
  }
//+------------------------------------------------------------------+
//| Sets chart scale (from 0 to 5)                                   |
//+------------------------------------------------------------------+
bool ChartScaleSet(const long value,const long chart_ID=0)
  {
//--- reset the error value
   ResetLastError();
//--- set property value
   if(!ChartSetInteger(chart_ID,CHART_SCALE,0,value))
     {
      //--- display the error message in Experts journal
      Print(__FUNCTION__+", Error Code = ",GetLastError());
      return(false);
     }
//--- successful execution
   return(true);
  }
Documentation on MQL5: Examples of Working with the Chart / Constants, Enumerations and Structures
Documentation on MQL5: Examples of Working with the Chart / Constants, Enumerations and Structures
  • www.mql5.com
This section contains examples of working with chart properties. One or two complete functions are displayed for each property. These functions...
 

If you want to capture double clicks, you'll need to time 2 clicks of CHARTEVENT_CLICK or CHARTEVENT_OBJECT_CLICK:

Documentation on MQL5: OnChartEvent / Event Handling
Documentation on MQL5: OnChartEvent / Event Handling
  • www.mql5.com
The function is called in indicators and EAs when the ChartEvent event occurs. The function is meant for handling chart changes made by a user or...