Closed-Bar True Range Gap Share Indicator
Advanced Trading Tutorial — MultiCharts .NET
Why distinguish a gap from traded range?
A large true range does not necessarily mean that prices traded through every level between its endpoints. A market may reopen far above the previous close and then trade in a narrow band. The usual range statistic combines the displacement and the subsequent trading range. This indicator separates the untraded portion between the prior close and the completed bar's range. It is a descriptive measure, not a prediction of whether a gap will fill.
Definition and worked examples
Let P be the close before the measured bar, H its high and L its low. True range is max(H,P) minus min(L,P). The external gap is max(0,L-P,P-H). Divide the external gap by true range and multiply by 100. A zero true range returns zero by convention. The result is bounded between zero and 100 for valid OHLC data. This is not the opening gap: an opening gap that fills during the bar produces zero external gap.
For P=100, H=102 and L=98, true range is 4 and gap is zero. For P=100, H=104 and L=102, true range is 4 and gap is 2, giving 50%. For P=100, H=105 and L=104, true range is 5 and gap is 4, giving 80%. A downward gap with H=98 and L=96 gives the same 50% as the second example. Direction is deliberately excluded.
Implementation and timing
The code uses the MultiCharts .NET indicator lifecycle. Create registers the plots once. CalcBar reads the preceding completed bar and the close before it, then writes a value at the current bar. This deliberate one-bar display offset avoids dependence on intrabar update settings. Do not interpret the value as information about the currently forming candle. The threshold is a visual reference, not an alert or order. The calculation is constant time and needs no rolling state. The first few bars are skipped conservatively to avoid invalid indexing.

Complete source code
using System;
using System.Drawing;
using PowerLanguage;
using PowerLanguage.Indicator;
namespace PowerLanguage.Indicator
{
[SameAsSymbol(true)]
public class PS_GapShare : IndicatorObject
{
private IPlotObject share;
private IPlotObject threshold;
[Input]
public double AlertLevel { get; set; }
public PS_GapShare(object ctx) : base(ctx)
{
AlertLevel = 50;
}
protected override void Create()
{
share = AddPlot(new PlotAttributes("GapShare",
EPlotShapes.Line, Color.RoyalBlue));
threshold = AddPlot(new PlotAttributes("Threshold",
EPlotShapes.Line, Color.SeaGreen));
}
protected override void StartCalc() { }
protected override void CalcBar()
{
// Use only the preceding completed bar.
if (Bars.CurrentBar < 3) return;
double prior = Bars.Close[2];
double hi = Bars.High[1];
double lo = Bars.Low[1];
double tr = Math.Max(hi, prior) - Math.Min(lo, prior);
// Portion of true range outside the traded bar range.
double gap = Math.Max(0, Math.Max(lo-prior, prior-hi));
double value = tr > 0 ? 100.0 * gap / tr : 0;
share.Set(value);
threshold.Set(Math.Max(0, Math.Min(100, AlertLevel)));
}
}
}
Installation and testing
Open PowerLanguage .NET Editor, create a new C# indicator named PS_GapShare, replace its generated class with the code, compile and insert it into a separate chart pane. If your editor generates a different namespace or class wrapper, retain that wrapper and adapt the class name. Use a threshold of 50 initially as a descriptive reference, not an optimized trading parameter. Load enough historical bars for the two backward references. The code has not been compiled in a live MultiCharts .NET installation.
Manually compare the three examples against the plot one bar later. Check a downward gap, a flat bar, and a bar that crosses the prior close. In a replay, record the value on the first tick of a new bar and compare it with subsequent ticks. It should remain unchanged when completed OHLC data remains unchanged. Reload the chart and compare historical values. Data corrections, session template changes, futures adjustments and missing bars may change the inputs and therefore the historical output. This is not future-data repainting.
Practical interpretation and limitations
Compare the gap share with absolute true range: an 80% share on a five-point range is different from 80% on a one-tick range. A high share may reflect a session break, thin liquidity, a corporate action or a futures rollover. It cannot establish whether trades actually occurred at every price within the high-low interval. On continuous intraday markets the metric may frequently be zero. Keep session settings and data adjustments consistent when comparing instruments. A threshold crossing alone does not establish a profitable entry. If incorporating this measure into a strategy, evaluate it alongside direction, liquidity, costs and out-of-sample data, and align the signal with its actual availability on the next bar.
For tailored filters and multi-data-series integration, see Custom MultiCharts .NET indicator Development Services.
Risk disclosure: Educational example only. Trading involves risk of loss; historical observations do not guarantee future results.