Script setting max and min values on a fixed scale chart

 

Hello!

When chart scale is set to fixed it is possible to drag the chart up and down, however when changing neighborly timeframes (especially the 1, 3 or 5 minutes) the margin to drag is way too little as it is probably calculated as the possible minimum to show the price action on the current timeframe.

The lame workaround is change timeframe into Monthly, scale the price action to fill the screen (double click or 5 from numpad) then change into the desired Minute chart and scale again. Which is annoying.

(Scaling the chart in such sequence sets the max and min values on the 3 minute chart based on the monthly and makes it available to drag the price action all the way between them)

Changed from 5 to 3 minute (you can only drag it 3 grid squares down and 1 up: 

https://charts.mql5.com/10/45/eurusd-m3-metaquotes-software-corp.png

Changed from 1 month to 3 minute (you can drag the whole price action out of the visible screen if you wish):

https://charts.mql5.com/10/45/eurusd-m3-metaquotes-software-corp-2.png

(the red pointers show the scroll bars)


I want an MT5 script to set automatically predefined max and min values when executed on the chart. I found this:

https://www.mql5.com/en/docs/constants/chartconstants/charts_samples#chart_fixed_max

but I know nothing of MQL5 language so far and I can't make a working script just by copy-pasting it into script template.

It shows error "function can be declared only in the global scope" which I don't know how to fix. Yet.


So, if anybody desires to lend some help on this before I read all the manual and post the ready script myself - you are welcome!


 

Here is the script if anybody ever find it useful:

//+------------------------------------------------------------------+
//|                                                      скръцпт.mq5 |
//|                         Copyright 2016, MegaKypec Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MegaKypec Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

//+------------------------------------------------------------------+
//| Sets the value of chart's fixed maximum and minimum.             |
//| To change the value of the property, CHART_SCALEFIX property     |
//| value should be preliminarily set to true.                       |
//+------------------------------------------------------------------+

bool ChartFixedMaxSet(const double value,const long chart_ID=0)
  {
//--- reset the error value
   ResetLastError();
//--- set property value
   if(!ChartSetDouble(chart_ID,CHART_FIXED_MAX,value))
     {
      //--- display the error message in Experts journal
      Print(__FUNCTION__+", Error Code = ",GetLastError());
      return(false);
     }
//--- successful execution
   return(true);
  }
  
bool ChartFixedMinSet(const double value,const long chart_ID=0)
  {
//--- reset the error value
   ResetLastError();
//--- set property value
   if(!ChartSetDouble(chart_ID,CHART_FIXED_MIN,value))
     {
      //--- display the error message in Experts journal
      Print(__FUNCTION__+", Error Code = ",GetLastError());
      return(false);
     }
//--- successful execution
   return(true);
  }

void OnStart()
  { ChartFixedMaxSet(2000,0);//вместо 2000 да се напише по-голямо число ако КУРса е ИЗКЛЮЧИТЕЛНО ГОЛЯМ 
    ChartFixedMinSet(0,0);
  }
//+------------------------------------------------------------------+

It's a direct copy-paste from the mql5 tutorial here:

https://www.mql5.com/en/docs/constants/chartconstants/charts_samples#chart_fixed_max


How to use it: 1. Set scale to "fixed" in chart properties 2. Execute script 3. Double-click on price axis or hit 5 from numpad

You should now be able to drag the price action up and down a lot.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Examples of Working with the Chart
Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Examples of Working with the Chart
  • www.mql5.com
Standard Constants, Enumerations and Structures / Chart Constants / Examples of Working with the Chart - Reference on algorithmic/automated trading language for MetaTrader 5
 

Changing "2000" with double the current price may actually make sence:

void OnStart()
  { ChartFixedMaxSet(2*SymbolInfoDouble(Symbol(),SYMBOL_BID),0); 
    ChartFixedMinSet(0,0);
  }
 
hi this is a good script here. really helpful. May I ask if anyone can also make an mt5 script for making the 'scale fix all charts' script so i can set it on a hotkey? instead of pressing F8 on every chart. (Since I change symbols through the enter key, and typing the symbol i want to analyze. scale fix resets all the time) Or perhaps you can include it with the script that you provided
thanks a lot!
Documentation on MQL5: Checkup / Symbol
Documentation on MQL5: Checkup / Symbol
  • www.mql5.com
Symbol - Checkup - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Indicator with a button: Scale Fix: how do i delete an erroneus bar - MQL5 programming forum 2020.04.01
 
William Roeder:
Indicator with a button: Scale Fix: how do i delete an erroneus bar - MQL5 programming forum 2020.04.01
thanks for the reply. Have noticed that it is a mq4 program. Is there any way to translate it for mq5? thanks

edit: thanks a lot managed to let it work on mt5
 
Jim Austria #:
thanks for the reply. Have noticed that it is a mq4 program. Is there any way to translate it for mq5? thanks

edit: thanks a lot managed to let it work on mt5
How did you get it to work on mt5???
 
kypa #:
ChartFixedMaxSet(2*SymbolInfoDouble(Symbol(),SYMBOL_BID),0);     ChartFixedMinSet(0,0);

thank you very much

Reason: