Download MetaTrader 5

Script setting max and min values on a fixed scale chart

To add comments, please log in or register
kypa
78
kypa  

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!


kypa
78
kypa  

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
kypa
78
kypa  

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

void OnStart()
  { ChartFixedMaxSet(2*SymbolInfoDouble(Symbol(),SYMBOL_BID),0); 
    ChartFixedMinSet(0,0);
  }
To add comments, please log in or register