Add vertical space / compress chart / y-axis scale - page 2

 
kayak:  Just tested this indi which looks quite interesting.
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
 
hugo:

Hi Mar,

Just found your post. I created this indicator a few months back to auto-scale the y-axis to show chart space above and below the current price candles/bars for my trading. Hope it is what you're after, or gives you some ideas.

(I am an amateur coder, so this code is provided "as is" and if any one is kind enough to improve or de-bug it - my thanks goes to you! It works for me currently)

 

VERY GOOD POST.

Your code is providing all of how to change the Y-axis scale on MQL5/4.

MQL5/4 don't provide explicit method to change the 'Y-axis scale' in MQL Standard Library except changing the MAX/MIN of charts.

 

Thanks but your indicator is absolutely useless - when using vertical scrolling - when a new tick arrives - it resets the chart for the min and max settings - you can make a normal vertical scrolling - so that the chart is centered only when switching timeframes - just look at how vertical scrolling is done in normal platforms like Ninja Trader - I understand that this indicator does not perform this function - just adjust it so that it does not return the chart as specified in the settings - that would he under a new tick remained to example as his the user shifted -- and returned graph in specified settings only under switching timeframes-i.e. was would a normal scrolling

 

Dear all, 

i had the same problem and now i found the solution. you can follow the next steps and enjoy the meta trader :) :) :) 

1. first right click and select indicator list

2. then choose the logarithmic scale, next in the right part, click the properties.

3. a new widows open , find the input tab and change the values of top/bottom free margins

good luck

 
Does anyone have this indicator for MT5? or something like it?
 
cwalker441 #:
Does anyone have this indicator for MT5? or something like it?
//--- Set free space at the top and bottom of the chart
void ChartVerticalSpace(double factor = 0.1) {
    long visible_bars = ChartGetInteger(0, CHART_VISIBLE_BARS);
    long first_bar = ChartGetInteger(0, CHART_FIRST_VISIBLE_BAR);
    long last_bar = first_bar - visible_bars + 1;
    double HH = iHigh(NULL, PERIOD_CURRENT, iHighest(NULL, 0, MODE_HIGH, visible_bars, last_bar));
    double LL = iLow(NULL, PERIOD_CURRENT, iLowest(NULL, 0, MODE_LOW, visible_bars, last_bar));
    double v_margin = (HH - LL) * factor;
    ChartSetDouble(0, CHART_FIXED_MAX, HH + v_margin);
    ChartSetDouble(0, CHART_FIXED_MIN, LL - v_margin);
    ChartRedraw();
}

int OnInit() {
    ChartSetInteger(0, CHART_SCALEFIX, true);
    //...
}

void OnDeinit(const int reason) {
    ChartSetInteger(0, CHART_SCALEFIX, false);
    //...
}

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam) {

    switch (id) {

        case CHARTEVENT_CHART_CHANGE: 
            if (lparam == 16) break;
            ChartVerticalSpace();
            break;

    //...
}
Reason: