Trading Tips — Measuring Directional Range Expansion in MultiCharts .NET
Price bars contain more information than their closing values. A market can establish higher highs and lower lows during the same candle, and the closing price alone cannot describe how much the observed price interval expanded in each direction. This tutorial develops a native PowerLanguage .NET indicator that compares positive extensions of consecutive high and low boundaries. The result is a bounded directional statistic accompanied by a simple validity flag. Its purpose is to help distinguish upward boundary extension from downward boundary extension, not to predict future prices or generate trading orders.
Define directional extensions explicitly
For a completed candidate bar, compare its high and low with the high and low of the immediately preceding bar. The upward extension is the larger of zero and candidate high minus preceding high. The downward extension is the larger of zero and preceding low minus candidate low. Both quantities are nonnegative. An inside bar generates zero for both; an outside bar can generate positive values in both directions. Unlike directional movement implementations that select only the larger of two competing movements, this definition retains both observations whenever both boundaries extend.
Over N completed comparisons, sum the upward and downward extensions separately to obtain U and D. When U+D is positive, calculate (U−D)/(U+D). This yields a score between −1 and +1. Positive values indicate larger accumulated upward extension, negative values indicate larger accumulated downward extension, and zero indicates equal accumulated extension. If U+D equals zero, no directional balance can be estimated. The implementation displays a neutral placeholder of zero and a separate HasExpansion value of zero in this situation. When expansion is present, HasExpansion is one.

Worked examples
Set the period to one. Assume the previous candle has a high of 110 and a low of 100. The candidate reaches 114 and 98. Its upward extension is four points and its downward extension is two points. The score is (4−2)/(4+2), approximately +0.333. Its activity flag is one. If the candidate instead has a high of 108 and a low of 102, both extensions are zero because the new interval remains within the old one. The score is then a placeholder of zero and the activity flag is zero. A different candidate with a high of 112 and a low of 98 also produces a score of zero, but its flag is one because equal positive extensions occurred on both sides.
For a multi-bar example, consider four chronological high-low intervals: 100–110, 98–114, 99–113 and 96–112. The three comparisons produce upward extensions of 4, 0 and 0, and downward extensions of 2, 0 and 3. Their totals are U=4 and D=5. The three-comparison score is therefore −1/9, approximately −0.111. Note that the algorithm sums extensions before dividing. It does not average individual bar ratios. A larger extension has more influence than a small extension, even when both have the same sign. All examples use hypothetical prices.
Complete PowerLanguage .NET C# source
using System;
using System.Drawing;
using PowerLanguage;
namespace PowerLanguage.Indicator
{
public class RangeExpansionBias : IndicatorObject
{
private IPlotObject bias;
private IPlotObject activity;
public RangeExpansionBias(object ctx) : base(ctx)
{
Period = 10;
}
[Input]
public int Period { get; set; }
protected override void Create()
{
bias = AddPlot(new PlotAttributes(
"ExpansionBias", EPlotShapes.Line, Color.RoyalBlue));
activity = AddPlot(new PlotAttributes(
"HasExpansion", EPlotShapes.Line, Color.Gray));
}
protected override void StartCalc()
{
}
protected override void CalcBar()
{
if (Period < 1) return;
// Set Maximum Bars Back >= Period + 1.
// Exclude the forming bar at offset zero.
double up = 0.0, down = 0.0;
for (int i = 1; i <= Period; i++)
{
// Compare each completed bar with its predecessor.
up += Math.Max(0.0, Bars.High[i] - Bars.High[i + 1]);
down += Math.Max(0.0, Bars.Low[i + 1] - Bars.Low[i]);
}
double total = up + down;
// Zero is a neutral placeholder when no expansion occurs.
bias.Set(total > 0.0 ? (up - down) / total : 0.0);
activity.Set(total > 0.0 ? 1.0 : 0.0);
}
}
}
Understand the study lifecycle and historical indexing
The class inherits from IndicatorObject. The constructor provides the default input, and the Input attribute exposes the period through the study settings. Create allocates two plot objects. The primary blue line displays the expansion bias; the gray line displays the activity flag. The latter should be interpreted as a Boolean validity indicator rather than a second directional oscillator. StartCalc is retained as part of the normal study lifecycle, although this direct implementation requires no persistent calculation state.
CalcBar uses offsets beginning at one. The bar at offset zero is deliberately excluded, regardless of whether the study is called during an intrabar update. For each candidate i, the previous bar is i+1. A Period of ten therefore requires access through offset eleven. The code relies on the platform's configured historical warm-up rather than attempting to infer available history from a potentially version-dependent index property. The loop requires O(N) work per calculation and reconstructs both sums from the same window on every call. It never increments a persistent counter merely because another tick arrives. This design makes it straightforward to compare historical references with the Data Window.
Installation and configuration
Open PowerLanguage .NET Editor, create a C# Indicator named RangeExpansionBias and replace its editable class with the supplied source. Compile the study and attach it to a separate chart pane. Configure Maximum Bars Back manually to at least Period+1, and increase this setting whenever Period increases. Use positive integer input values. This example assumes a single primary bar series and does not synchronize secondary instruments or timeframes. Begin with Period=10, then temporarily set Period=1 or Period=3 to check the numerical examples. The source has not been compiled or run in MultiCharts .NET here. Verify the build, plot configuration and historical access in your installed version before relying on it.
Closed-bar alignment and repainting
The observation displayed at bar t uses comparisons ending no later than t−1. This means the last input candle is completed before it becomes eligible. If intrabar indicator updates are enabled, the observation can be calculated when the next bar first appears and remains stable during ordinary price updates of that bar. If the study is configured for close-only execution, the same observation may be displayed later, when the current bar closes. Account for this alignment difference when comparing the output with indicators that calculate on the current completed bar. The code does not reference future prices and does not intentionally repaint confirmed observations. Data corrections, session changes and rebuilt synthetic bars can nevertheless alter historical calculations.
Testing, interpretation and limitations
Manually compare the indicator with inside bars, outside bars, equal boundary extensions, upward-only extension and downward-only extension. Confirm that the activity flag distinguishes genuine balance from an inactive window. Test the earliest calculation after warm-up and reload the chart with identical data and session settings. If the study is consumed by another program, verify the timestamp at which the result becomes available. A high positive score does not necessarily mean the close advanced, and a high negative score does not establish a bearish forecast. A very small total extension can yield the same extreme ratio as a large one. Researchers may benefit from adding the total extension as a separate magnitude measure. This study ignores volume, the sequence of trades inside a candle, spread and execution costs. Test any proposed use on independent data with realistic trading assumptions.
For minimum-expansion filters, adaptive reference windows, alerts or strategy integration, contact our Custom MultiCharts .NET indicator Development Services.
Risk disclosure: educational material only. Trading involves risk of loss. Hypothetical examples do not establish profitability.