MultiCharts PowerLanguage Range Expansion Ratio Indicator: Compare Candle Size with Its Prior Average
Beginner Trading Tutorial | MultiCharts | Classic PowerLanguage Indicator
A large candle can stand out on a chart, but visual size alone is not an objective measure of how unusual its range is. A four-point candle may be routine during an active session and exceptional during a quiet period. Instead of assigning the same absolute threshold to every market condition, we can compare the current candle's high-to-low range with a rolling reference based on earlier candles.
This tutorial builds a complete classic PowerLanguage indicator for MultiCharts that displays a range expansion ratio. It uses the current high minus low as the numerator and the mean range of the preceding N bars as the denominator. The indicator provides an accessible starting point for research into changing price activity without assuming that a large candle predicts a particular direction.
Start with a clear definition
Let R(t) = High(t) − Low(t). Define the reference mean as the arithmetic average of R(t−1) through R(t−N), where N is a user-defined positive whole number. The indicator calculates Range Expansion Ratio = R(t) / mean of previous N ranges. A value of one means the current range equals the preceding mean; two means it is twice that mean; one half means it is half as large.
This is a high-low range comparison, not an Average True Range (ATR) comparison. True range also considers the distance from the previous close. A market that gaps sharply and then trades within a narrow range could have a small high-low expansion ratio despite substantial movement relative to yesterday's close. The distinction matters when choosing an indicator for gap-sensitive research.

In the illustration, four preceding ranges total 16 price units, and their mean is four. The current candle has a high-low range of eight, so its ratio is 8 / 4 = 2.00. If the same current range were included in a rolling four-bar average, the oldest range of three would be dropped and the reference would become (5 + 4 + 4 + 8) / 4 = 5.25. The resulting ratio would be approximately 1.52 instead. Neither convention should be selected accidentally. Our prior-only reference measures the new observation against a benchmark formed before that observation.
| Current range | Prior mean | Ratio | Meaning |
|---|---|---|---|
| 8 | 4 | 2.00 | Twice the prior average |
| 4 | 4 | 1.00 | Equal to the prior average |
| 2 | 4 | 0.50 | Half the prior average |
| 0 | 4 | 0.00 | Flat current bar |
| 8 | 0 | Undefined | Invalid reference |
All example values are hypothetical. A zero current range can be a legitimate measurement if the reference is positive. A zero reference, however, makes the ratio undefined and must not be replaced with an arbitrary value.
Complete PowerLanguage source code
{ PatternSmart Range Expansion Ratio
MultiCharts classic PowerLanguage indicator }
Inputs:
Lookback(20);
Variables:
BarRange(0),
PriorMean(0),
RangeRatio(0);
{ Configure MaxBarsBack to at least Lookback + 1.
Use bar-close calculation for confirmed readings. }
BarRange = High - Low;
If Lookback >= 1 Then
Begin
{ The reference uses only earlier bars. }
PriorMean = Average(High[1] - Low[1], Lookback);
Plot2(1, "Baseline");
If PriorMean > 0 and BarRange >= 0 Then
Begin
RangeRatio = BarRange / PriorMean;
Plot1(RangeRatio, "RangeRatio");
End
Else
NoPlot(1);
End
Else
Begin
NoPlot(1);
NoPlot(2);
End;
Understand the calculation sequence
The Inputs declaration exposes Lookback, which defaults to 20 bars. Variables hold the current range, the prior mean and the result. On every calculation, BarRange receives High minus Low. The Average function is applied to High[1] minus Low[1], so the latest observation in the reference is the preceding bar. With a lookback of four, it covers offsets one through four rather than zero through three.
The code plots a constant reference at 1 using Plot2. Plot1 represents the computed ratio and is plotted only when the reference is positive and the current range is nonnegative. NoPlot suppresses the ratio on an invalid observation. This distinction prevents a data-quality or zero-denominator problem from being misread as a legitimate flat bar.
Enter a positive integer for Lookback. The condition checks that the input is at least one, but this example does not implement a separate fractional-input rounding policy. The indicator is intended for ordinary chart data with consistent high and low values. It contains no order instructions or trading-system logic.
MaxBarsBack and initial history
MultiCharts requires sufficient history before evaluating studies that reference previous bars. MaxBarsBack governs the number of preceding bars reserved for the calculation. In the indicator's study properties, use automatic detection where appropriate or specify a conservative value of at least Lookback + 1. For the default lookback of 20, a manual setting of 21 is sufficient for this simple implementation. When increasing Lookback, review the manual history setting as well. A chart with too little loaded data cannot establish the reference reliably.
Do not infer that the absence of an initial plot means the range ratio is zero. The platform may simply be withholding output until adequate history is available. MultiCharts can recalculate a study when its automatically detected historical requirement changes, which is another reason to verify the warm-up behavior after adjusting inputs.
Bar-close versus intrabar calculations
In the Format Indicator properties, disable Update on Every Tick if you want the study to evaluate completed candles in real time. Historical bars are normally evaluated using their completed values. When tick updates are enabled, the current high-low range can expand as new extremes occur. The earlier-bar reference usually stays fixed during that bar, but the current ratio may change before the bar closes.
For example, a candle with a prior reference of four may initially have a range of one and a ratio of 0.25. If its high-low range later reaches six, the live ratio becomes 1.50. That is a developing-bar measurement, not a contradiction of the final historical result. To reproduce a closed-bar research rule, use completed-bar observations consistently. The code itself relies on the study's calculation setting rather than imposing an additional BarStatus filter.
Choose the lookback for your objective
| Lookback | Behavior |
|---|---|
| 5 | Quick adaptation to recent candle sizes |
| 20 (default) | Moderate rolling reference |
| 50 | Slower-moving reference across a longer interval |
A short lookback quickly incorporates recent expansion bars into the baseline. After an unusually wide candle, subsequent candles may therefore appear less exceptional. A longer lookback retains older ranges for more observations, but may combine periods of different volatility. Neither is automatically superior. Compare settings on the same symbol, bar type and timeframe before deciding whether the feature is useful.
Installation and manual verification
- Open the classic MultiCharts PowerLanguage Editor, not the .NET editor.
- Create a new Indicator study named PSRangeExpansionRatio and paste the complete source.
- Compile or verify the study and review any diagnostics.
- Insert the indicator on a standard candlestick chart, in a separate subchart, and use a positive integer Lookback.
- Review MaxBarsBack and disable Update on Every Tick for closed-bar research.
- Set Lookback to four, read five consecutive completed high-low ranges, average the first four and divide the fifth by that reference. Compare the result with Plot1.
Repeat the check for a small candle, a large candle and a flat observation where available. Confirm that Plot2 stays at one during valid calculations. Change the lookback and ensure that sufficient history remains loaded. In a live chart, compare the tick-update setting on and off to understand which observations are provisional. If a plot is missing, inspect history availability and whether the earlier mean is zero before assuming a software fault.
Applications and limitations
Range expansion can be used as a descriptive feature for identifying unusually active bars, comparing recent market regimes or building research filters. The indicator is direction-neutral: an upward candle and a downward candle with the same range receive the same ratio. It does not measure traded volume, gap-inclusive volatility, spread or execution quality. Fixed-range chart types can also make this comparison less informative because their construction constrains bar sizes. Session transitions and contract rollovers may distort the reference, so define the data universe carefully.
If you want to extend this free indicator with gap-aware calculations, session-specific baselines, alerts or strategy integration, contact us through our Custom Trading Software Development Services.
The source was reviewed against MultiCharts documentation for study settings and history handling but has not been compiled or executed in the platform. Validate it independently before use. Trading involves risk; a large range does not guarantee future price movement or profitability.