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); }
- www.mql5.com
If you want to capture double clicks, you'll need to time 2 clicks of CHARTEVENT_CLICK or CHARTEVENT_OBJECT_CLICK:
- www.mql5.com
This should get you started:
Thanks for the help, but handling chart scale I alredy know and it is implemented. My problem is just replicating the chart behaviour of double-clicking the Y axis at the right.
If you want to capture double clicks
No, not capture; I want to replicate with code the chart's behaviour when the Y axis is double-clicked.
MT5 auto reset Fixed Price Min/Max
Thanks, but that doesn't work: if I set any value to FIXED max/min, my goal is lost. I need the maximum and minimum price values to be set without any change to the FIXED values.
I want to replicate with code the chart's behaviour when the Y axis is double-clicked.
[I]f I set any value to FIXED max/min, my goal is lost. I need the maximum and minimum price values to be set without any change to the FIXED values.
If a picture is worth a thousand words, a video is worth a million. I now see that you're making an MT5 chart operate like a TradingView chart─without using a chart template.
I had another look at the MQL5 chart events and I see what you mean. There is no double click/snap chart event. For whatever it's worth, I have noticed in the past that ChartRedraw() seemed to "inadvertently" snap the chart to the height of visible bars when called. That might be a workaround, albeit a rather blunt one.
Hi,
I'd like to reproduce as code the following steps:
- Scale to max zoom out
- Increase the value of the min and maximum Y axis (so, if it's plotting $10 - $20, the scales will be like $5 - $25).
- Set scales to fix mode
- Scale to "normal", original zoom
- Double-click over the Y axis
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).
The "double-click" behavior on the Y-axis is essentially a shortcut to toggle off Scale Fixed and return to Auto Scaling. When you do this, MT5 recalculates the visible range automatically.
To replicate this via code without losing your fixed bounds permanently, you should toggle the CHART_SCALEFIX property. Try this sequence:
// 1. Disable Fixed Scale to trigger MT5's auto-calculation ChartSetInteger(0, CHART_SCALEFIX, false); // 2. Force a redraw to let the terminal recalculate min/max ChartRedraw(0); // 3. (Optional) If you need to return to fixed mode with the new "snapped" values: double autoMax = ChartGetDouble(0, CHART_PRICE_MAX); double autoMin = ChartGetDouble(0, CHART_PRICE_MIN); ChartSetInteger(0, CHART_SCALEFIX, true); ChartSetDouble(0, CHART_FIXED_MAX, autoMax); ChartSetDouble(0, CHART_FIXED_MIN, autoMin);
This approach forces the terminal to perform the "snap" you see in the video by momentarily letting the built-in auto-scale engine take over.
The "double-click" behavior on the Y-axis is essentially a shortcut to toggle off Scale Fixed and return to Auto Scaling. When you do this, MT5 recalculates the visible range automatically.
To replicate this via code without losing your fixed bounds permanently, you should toggle the CHART_SCALEFIX property. Try this sequence:
This approach forces the terminal to perform the "snap" you see in the video by momentarily letting the built-in auto-scale engine take over.
This approach forces the terminal to perform the "snap" you see in the video by momentarily letting the built-in auto-scale engine take over.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I'd like to reproduce as code the following steps:
- Scale to max zoom out
- Increase the value of the min and maximum Y axis (so, if it's plotting $10 - $20, the scales will be like $5 - $25).
- Set scales to fix mode
- Scale to "normal", original zoom
- 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).