Advanced Trading Tutorial — MultiCharts PowerLanguage indicator development

Two observation windows can contain the same total high-low range while distributing that range very differently across their constituent bars. In one window, nearly every candle contributes a similar amount of price variation. In another, one unusually wide candle accounts for most of the total. A conventional average range reports the same number for both windows, even though their internal structure is different. The Range Concentration Index developed in this tutorial measures how unevenly the total observed range is allocated across completed bars. It is an adaptation of the mathematical concentration index often used to describe shares, rather than a directional trading signal.

From individual ranges to a normalized concentration measure

Let N be the number of completed bars and let R be the high minus the low of each bar. Calculate S, the sum of all N ranges, and Q, the sum of their squares. When S is positive, each bar has a range share equal to its individual range divided by S. The sum of the squared shares is Q divided by S squared. This is a Herfindahl-style concentration measure, commonly abbreviated HHI. Squaring the shares makes large contributors disproportionately influential. If all ranges are equal and positive, the raw measure is 1/N. If exactly one range is positive, it is one.

Because the minimum raw value depends on the number of observations, normalize the result to a zero-to-one-hundred scale. The normalized score is 100 times (N times HHI minus one) divided by (N minus one). Zero represents equal positive ranges and one hundred represents a window in which a single bar supplies all the range. Intermediate results describe degrees of concentration. This normalization aligns the mathematical endpoints for different lookbacks, but it does not imply that the resulting empirical distributions are equivalent across all periods or markets.

When all ranges are zero, there is no positive total to distribute. The indicator suppresses its measurement instead of classifying the window as perfectly uniform or maximally concentrated. The fixed reference level of 25 is a visual aid and is not a calibrated decision threshold.

Worked example: the same total, different allocation

Suppose four completed candles have high-low ranges of 2, 3, 5 and 10 price units. Their total is 20 and their squared total is 4 + 9 + 25 + 100 = 138. The raw HHI is 138/400 = 0.345. With N equal to four, the normalized score is 100 times (4 times 0.345 minus 1) divided by 3, or approximately 12.67. Compare this with four ranges of 5, 5, 5 and 5: total range is still 20, but the raw HHI is 0.25 and the normalized score is zero. If all twenty units belong to one bar, the normalized score is one hundred. These hypothetical observations show why concentration adds information beyond the arithmetic mean.

Range Concentration Index: Measuring Uneven Distribution of Bar Ranges
The four ranges contribute 10%, 15%, 25% and 50% of total range. Squared shares sum to 0.345; the normalized four-bar index is 12.67.

Complete PowerLanguage indicator

{ Range Concentration Index - PowerLanguage indicator }
Inputs: Lookback(20);
Vars: N(0), J(0), Rng(0), TotalRng(0),
      TotalSquared(0), HHI(0), Score(0);

{ Use a bounded integer period. }
N = IntPortion(Lookback);

if N >= 2 and N <= 500 then begin
    { Exclude the currently forming bar. }
    TotalRng = 0;
    TotalSquared = 0;

    for J = 1 to N begin
        Rng = High[J] - Low[J];
        TotalRng = TotalRng + Rng;
        TotalSquared = TotalSquared + Rng * Rng;
    end;

    if TotalRng > 0 then begin
        HHI = TotalSquared / (TotalRng * TotalRng);
        { Normalize equal ranges to 0, single contributor to 100. }
        Score = 100 * (N * HHI - 1) / (N - 1);
        Score = MaxList(0, MinList(100, Score));
        Plot1(Score, "Concentr");
        SetPlotColor(1, Blue);
    end
    else NoPlot(1);

    Plot2(25, "Reference");
    SetPlotColor(2, DarkGray);
end
else begin
    NoPlot(1);
    NoPlot(2);
end;

Installation and historical data requirements

Open the PowerLanguage Editor and create a new Indicator named RangeConcentrationIndex. Paste the source and compile it. Add the study to a normal chart, preferably in a separate subchart. Set its MaxBarsBack explicitly to at least the intended Lookback value because the loop references historical bars dynamically. If you subsequently increase the Lookback input, adjust MaxBarsBack accordingly and reload the study. The code permits integer periods from two through five hundred; fractional inputs are truncated by IntPortion. The source has not been compiled in a running MultiCharts installation for this article, so local compilation and data verification are required.

Why the most recent completed bar is at index one

The calculation uses High[1] through High[N] and their matching lows. It intentionally excludes bar zero regardless of the chart's update mode. Thus the score shown at the current bar describes the N completed bars immediately preceding it. At the first tick of a new bar, the just-completed bar enters the sample. If the study is configured to calculate only at bar close, the display updates on that close but still excludes that bar; this is a conservative one-bar lag. Enable intrabar updating if you want the prior completed window displayed as soon as the next bar starts. The result is stable throughout a forming bar when the preceding price history is unchanged.

There is no forward indexing and no use of a future window. Historical data revisions, changes in chart session configuration and different bar construction can still modify observations. This is especially important when comparing time bars with range bars, because a chart type that mechanically restricts bar range can suppress the variation the indicator seeks to describe.

Parameter selection and computational considerations

A short observation window responds strongly when an exceptionally wide bar enters or leaves the sample. A longer window distributes shares across more observations and may dilute a single extreme, although an extraordinary event can remain influential until it exits the window. The default is twenty completed bars. The code uses a single loop with linear work in the selected period and constant auxiliary storage. This approach is simple to audit and avoids recursive state, rolling-array synchronization, and subtractive cancellation associated with some incremental calculations. If a large symbol universe requires faster execution, profile the existing implementation first and validate any rolling optimization against these direct sums.

Validation checklist

  • Set Lookback to four with sufficient MaxBarsBack and compare the hypothetical 12.67 result against a spreadsheet.
  • Check equal positive ranges, which should produce zero, and one positive range with all others zero, which should produce one hundred.
  • Check an all-zero window: the measurement plot should be absent.
  • Scale every range by the same positive factor and verify the score remains unchanged.
  • Confirm that price changes on the currently forming bar do not affect the prior-window score.
  • Verify the displayed timestamp alignment and compare matching datasets after reloading the study.

Interpretation and limitations

Concentration says nothing about whether the wide bars were bullish or bearish. It does not measure close-to-close gaps, traded volume, order-book liquidity, or the sequence of trades inside the bar. A high value can reflect a scheduled announcement, a data anomaly, or a genuinely concentrated burst of activity; the statistic cannot identify the cause. A low value can occur in both quiet and volatile markets as long as the bar ranges are similarly distributed. Combine it with a separate absolute range measurement when overall volatility matters. If you are interested in extending this free study with session filtering, gap-aware inputs or integration into a custom signal, contact us through our Custom MultiCharts indicator Development Services.

Trading involves risk of loss. The indicator and examples are educational and do not establish profitable trading rules. Validate the source, chart settings, historical data and execution assumptions before using derived signals with real capital.

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.