Beginner Trading Tutorial — Confirmed Range Expansion Ratio in MultiCharts .NET

One of the simplest ways to investigate changes in market activity is to compare the size of consecutive price bars. A candle with a range of eight price units may appear substantial, but its meaning depends on the preceding observation. If the preceding range was four, the current range is twice as large; if it was sixteen, the current range is only half as large. This tutorial develops a native PowerLanguage .NET indicator that expresses this comparison as a percentage and deliberately uses completed bars only. The calculation is transparent enough for a beginner to verify with a calculator, while illustrating an important distinction between a plotted value and the time at which that value becomes available.

Define the measurement

The ordinary range of a candle is its high minus its low. Let R be the range of the most recent completed candle and P be the range of the completed candle immediately preceding it. The expansion ratio is 100 multiplied by R divided by P. A reading of 100 means equal ranges. A reading below 100 means contraction relative to that reference; a reading above 100 means expansion. A reading of 200 means that the recent range is twice the reference range, not that the price has risen by 200 percent.

Because the denominator must be positive, a zero-width reference candle makes the calculation undefined. A valid zero-width recent candle with a positive reference produces zero. The implementation distinguishes these cases by reserving minus one as an invalid-data sentinel. Valid percentages are nonnegative and have no fixed upper bound. A very small reference can therefore generate a very large value, even when the current bar is not unusually large in absolute terms.

Confirmed Range Expansion Ratio Indicator
Three independent hypothetical comparisons use the same preceding range of four price units. Recent ranges of two, four and eight give 50%, 100% and 200%, respectively. The horizontal line marks the reference magnitude.

Work through three examples

Suppose the preceding completed candle has a high of 104 and a low of 100. Its range is four. In case A, the latest completed candle has a high of 105 and a low of 103. Its range is two, giving 50%. In case B, its high is 107 and low is 103, giving a range of four and a ratio of 100%. In case C, its high is 110 and low is 102, giving a range of eight and a ratio of 200%. These are separate hypothetical alternatives, not successive bars. The candle's opening and closing prices do not affect the formula.

If the reference high and low are both 100, the denominator is zero and the indicator reports minus one rather than pretending that volatility contracted. Conversely, if the recent high and low are both 103 and the reference range remains four, the valid result is zero. This distinction is important for automated consumers that may otherwise mistake missing data for extreme compression.

Complete PowerLanguage .NET C# source

using System;
using System.Drawing;
using PowerLanguage;

namespace PowerLanguage.Indicator
{
    public class PSConfirmedRangeExpansion : IndicatorObject
    {
        private IPlotObject ratio;
        private IPlotObject baseline;

        public PSConfirmedRangeExpansion(object ctx)
            : base(ctx) { }

        protected override void Create()
        {
            ratio = AddPlot(new PlotAttributes(
                "Range Percent", EPlotShapes.Histogram,
                Color.SteelBlue));
            baseline = AddPlot(new PlotAttributes(
                "Reference", EPlotShapes.Line,
                Color.Gray));
        }

        protected override void StartCalc()
        {
            // No persistent state is required.
        }

        protected override void CalcBar()
        {
            // Use two preceding bars, never the forming bar.
            // Output at the current index intentionally
            // represents the previous completed observation.
            double recent = Bars.High[1] - Bars.Low[1];
            double reference = Bars.High[2] - Bars.Low[2];

            baseline.Set(100.0);

            // Negative output is reserved for invalid data.
            if (reference <= 0.0 || recent < 0.0 ||
                double.IsNaN(reference) ||
                double.IsNaN(recent) ||
                double.IsInfinity(reference) ||
                double.IsInfinity(recent))
            {
                ratio.Set(-1.0);
                return;
            }

            ratio.Set(100.0 * recent / reference);
        }
    }
}

Understand the study lifecycle

The class derives from IndicatorObject and uses the constructor pattern that supplies the platform context to the base class. Create allocates two plot objects. One displays the measured percentage as a histogram, and the other draws a horizontal line at 100. StartCalc is present as part of the normal study lifecycle but needs no persistent initialization because each result is calculated independently. CalcBar reads the required price arrays and writes the plot values for the current calculation index.

The important design decision is that Bars.High[1] and Bars.Low[1] describe the previous bar, while index two supplies its predecessor. The current bar at index zero is never used. Unlike a design that retrospectively writes onto the previous candle, this example places the confirmed reading at the current calculation index. The plot therefore has an intentional one-bar alignment delay relative to the candle being measured. That convention makes it possible to see the value at the bar where it becomes available rather than suggest that it was known during the measured candle.

Set the study's maximum bars back to at least two in the study properties before running it. The platform must supply both historical offsets before CalcBar is evaluated. The source does not attempt to infer a missing history policy from the current bar number. The calculation is constant time per bar and does not use any external library beyond standard platform and .NET references.

Installation and verification

Open PowerLanguage .NET Editor and create a new indicator named PSConfirmedRangeExpansion. Replace the generated indicator class with the full code, compile it and review any compiler diagnostics. Insert the indicator into a chart in MultiCharts .NET, choose a separate subchart for the display and configure maximum bars back to at least two. The reference line should appear at 100 and the histogram should display the relative range percentage. Check the exact values in the chart's data inspection interface rather than estimating them visually. This code has not been compiled or executed in the platform here.

Closed-bar behavior and repainting

During an active candle its high and low may change, but this indicator uses only indices one and two. Consequently, repeated intrabar evaluations of the same calculation index should return the same value when the two preceding bars are unchanged. The next chart bar advances the reference window. If the study is configured to calculate only at bar close, the display may not update until that calculation occurs; enable intrabar updating when you need the previous-bar result during the new bar and verify the actual scheduling in your installed version. Historical data corrections, session changes and reconstructed bars can still change results legitimately.

Testing and limitations

Verify the three examples, then test a zero reference range, a zero recent range, equal ranges and a sequence of unusually small reference ranges. Compare a spreadsheet calculation with the indicator while accounting for the intentional one-bar alignment. During replay, inspect the result as the active candle expands and confirm that its provisional range does not enter the formula. Reload the chart with identical settings and compare the historical values. A ratio above 100 does not specify a bullish or bearish direction, and a ratio below 100 does not guarantee a subsequent breakout. The formula ignores gaps from the previous close, volume, spread and liquidity. It compares just two observations, so it can be noisy. Use independent samples and realistic execution costs when investigating any downstream trading rule.

For multi-bar baselines, configurable thresholds, gap-adjusted measures or integration with a custom signal, contact our Custom MultiCharts .NET indicator Development Services.

Risk disclosure: educational content only. Trading involves risk of loss. Hypothetical examples do not establish 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.