Advanced Trading Tutorial — Range Compression Ratio in MultiCharts

Volatility is not constant. A market that has recently traded through wide intrabar ranges may subsequently enter a quiet phase, while a previously quiet market may begin to expand. A fixed point threshold does not adapt well to different instruments or changing market conditions. This tutorial develops a relative range indicator in PowerLanguage that compares two adjacent, non-overlapping windows. It describes changes in intrabar activity without attempting to predict breakout direction.

Define the two windows

Calculate the arithmetic mean of high minus low for the latest N completed bars. Divide that mean by the corresponding mean for the M bars immediately preceding those N bars. A ratio of one indicates equal average ranges. A ratio below one indicates contraction relative to the baseline; a ratio above one indicates expansion. The denominator deliberately excludes the recent window, preventing the new volatility observations from simultaneously changing their own reference sample.

Range Compression Ratio Indicator
A hypothetical baseline average range of 10 points and recent average of 5 points produce a ratio of 0.50.

Worked examples

For a small manual example, set both lengths to three. Suppose the older three ranges are 8, 10 and 12 points. Their mean is 10. The newer three ranges are 4, 5 and 6 points, with a mean of 5. The ratio is 0.50. In a separate hypothetical example, newer ranges of 12, 15 and 18 produce a mean of 15 and a ratio of 1.50 against the same baseline. Equal means produce 1.00. A baseline consisting entirely of zero-range bars cannot support a meaningful ratio and should produce no plotted observation.

Native PowerLanguage implementation

The code uses Average to compute each window and the historical reference operator to shift the baseline average backward by the recent length. Plot1 displays the ratio and Plot2 displays a reference line at one. Green marks values below 0.7, red marks values above 1.3, and blue marks the remaining values. These colors identify volatility regimes, not long and short recommendations. The thresholds are illustrative rather than optimized.

Inputs: RecentLength(5), BaseLength(20);
Variables: RecentMean(0), BaseMean(0), Ratio(0);

// Set MaxBarsBack to at least RecentLength + BaseLength.
// Use two non-overlapping windows of completed bars.
If RecentLength >= 1 and BaseLength >= 1 then begin
    If BarStatus(1) = 2 then begin
        RecentMean = Average(High - Low, RecentLength);
        BaseMean = Average(High - Low, BaseLength)[RecentLength];
        If BaseMean > 0 then begin
            Ratio = RecentMean / BaseMean;
            Plot1(Ratio, "RangeRatio");
            If Ratio < 0.7 then
                SetPlotColor(1, Green)
            else if Ratio > 1.3 then
                SetPlotColor(1, Red)
            else
                SetPlotColor(1, Blue);
        end
        else NoPlot(1);
        Plot2(1, "Baseline");
    end;
end;

Installation and execution

Open the PowerLanguage Editor in classic MultiCharts, create a new Indicator named RangeCompressionRatio, paste the source and compile. Insert the study into a chart and place it in a separate subchart. Use positive integer input lengths. Configure MaxBarsBack manually to at least the sum of the two lengths, increasing it when the lengths change. This conservative setting ensures that the shifted baseline average has sufficient historical data. Disable intrabar indicator updating for a closed-bar workflow; the BarStatus check additionally restricts the plotting block to closing updates of Data1. This example is intended for a single data series.

Repainting and validation

The calculation uses current and earlier completed bars only. It does not use future references or a centered moving average. Under ordinary closed-bar operation, confirmed values are not intentionally repainted. Historical data corrections, session changes and reconstructing synthetic bars may alter the historical results. Check the first valid observation after the warm-up, the zero-denominator case and a chart reload. Compare the ratio against manually calculated window averages, especially at the boundary between the recent and baseline windows. The code has not been compiled or executed in MultiCharts here.

Research considerations

A compression reading can persist for many bars, and a subsequent expansion does not guarantee a profitable breakout. A low ratio may reflect a quiet session, reduced liquidity or a temporary change in market participation. High minus low excludes gaps between bars, so a market with large overnight gaps may appear less volatile than a true-range-based alternative. A very small positive baseline can produce extreme ratios. Consider a minimum baseline filter when studying illiquid instruments. Evaluate any proposed thresholds on independent data, and account for commissions, slippage and execution constraints. The ratio is not bounded above and does not contain directional information.

For adjustable thresholds, ATR-based variants or integration with a trading signal, contact our Custom MultiCharts indicator Development Services.

Risk disclosure: educational material only. Trading involves risk of loss; hypothetical examples do not demonstrate profitability.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.