Intermediate Trading Tutorial — Confirmed Midpoint Migration Consistency in MultiCharts .NET
Two price sequences may travel the same net distance while exhibiting very different patterns of directional movement. One may climb through a succession of small advances; another may alternate between large advances and declines. Measuring endpoint displacement alone cannot distinguish how often the intermediate observations moved in each direction. This tutorial builds a native MultiCharts .NET C# indicator that classifies the movement of consecutive candle range midpoints, counts upward and downward changes, and reports their frequencies along with a signed difference. Its focus is directional consistency, not the size of individual price changes or a prediction of future market direction.
Establish the midpoint and classification rule
For each candle define its range midpoint as the sum of its high and low divided by two. This is a geometric midpoint of the observed price range, not the volume-weighted average transaction price. Calculate a change by subtracting the preceding candle's midpoint from the current evaluated midpoint. Let T be a nonnegative deadband expressed in raw price units. A change strictly greater than T qualifies as upward, and one strictly below negative T qualifies as downward. Changes between those bounds, including equality at either boundary, are neutral. With T equal to zero, any strictly positive or negative change qualifies, while an unchanged midpoint is neutral.
Across N completed changes, let U denote the upward count and D the downward count. The upward frequency is 100 × U/N, and the downward frequency is 100 × D/N. Subtract the latter from the former to obtain the net frequency in percentage points. Neutral changes remain in the denominator. Each frequency is bounded between zero and one hundred percent, and their sum cannot exceed one hundred percent. The net is bounded between minus one hundred and plus one hundred percentage points. It is not a return or a relative percentage difference. A valid zero net may reflect equal opposing counts or a completely neutral sample.

Calculate the example by hand
Set Period to five and MinimumMove to zero. Assume six successive high/low pairs are 101/99, 103/101, 102/100, 104/102, 104/102 and 105/103. The corresponding midpoints are 100, 102, 101, 103, 103 and 104. Their five changes are +2, −1, +2, 0 and +1 price units. Three changes are positive, one is negative and one is neutral. Therefore upward frequency is 60%, downward frequency is 20%, and net is +40 percentage points.
Now use the same sample but set MinimumMove to one. Only the two +2 changes qualify upward. The −1 and +1 changes are exactly at the deadband boundaries and therefore neutral. The unchanged midpoint also remains neutral. The new outputs are 40% upward, 0% downward and +40 percentage points net. Notice that the net happens to remain the same even though the composition changes considerably. This illustrates why displaying both directional frequencies is more informative than relying on their difference alone. These are independent hypothetical calculations, not observed trading results.
Complete native C# indicator source
using System;
using System.Drawing;
using PowerLanguage;
namespace PowerLanguage.Indicator
{
public class PSMidpointMigration : IndicatorObject
{
private IPlotObject upPlot;
private IPlotObject downPlot;
private IPlotObject netPlot;
[Input]
public int Period { get; set; }
[Input]
public double MinimumMove { get; set; }
public PSMidpointMigration(object ctx) : base(ctx)
{
Period = 20;
MinimumMove = 0.0;
}
protected override void Create()
{
upPlot = AddPlot(new PlotAttributes(
"UpPct", EPlotShapes.Line, Color.SeaGreen));
downPlot = AddPlot(new PlotAttributes(
"DownPct", EPlotShapes.Line, Color.IndianRed));
netPlot = AddPlot(new PlotAttributes(
"NetPP", EPlotShapes.Line, Color.SteelBlue));
}
protected override void StartCalc()
{
}
protected override void CalcBar()
{
// Manually set MaxBarsBack to at least Period + 1.
// Exclude the current forming bar at offset zero.
if (Period < 1 || Period > 10000 ||
MinimumMove < 0 ||
double.IsNaN(MinimumMove) ||
double.IsInfinity(MinimumMove))
return;
int up = 0, down = 0;
for (int i = 1; i <= Period; i++)
{
double h1 = Bars.High[i];
double l1 = Bars.Low[i];
double h2 = Bars.High[i + 1];
double l2 = Bars.Low[i + 1];
if (h1 < l1 || h2 < l2)
return;
// Midpoint change in raw price units.
double change = ((h1 + l1) -
(h2 + l2)) / 2.0;
if (double.IsNaN(change) ||
double.IsInfinity(change))
return;
// Equality at either deadband boundary is neutral.
if (change > MinimumMove)
up++;
else if (change < -MinimumMove)
down++;
}
double upPct = 100.0 * up / Period;
double downPct = 100.0 * down / Period;
upPlot.Set(upPct);
downPlot.Set(downPct);
netPlot.Set(upPct - downPct);
}
}
}
Implementation and historical indexing
The indicator derives from IndicatorObject in the PowerLanguage.Indicator namespace. The constructor initializes the default inputs, while Create defines three numerical line plots with distinct colors. StartCalc is included as the standard lifecycle method; no persistent accumulator is required. CalcBar calculates the statistic directly from the historical price series. Period is the number of changes, so a sample requires Period plus one completed range midpoints. MinimumMove uses the price scale of the instrument, not a fixed number of ticks. For example, on a symbol with a 0.25 minimum price increment, a deadband of 0.5 price units corresponds to two such increments; the strict comparison still excludes changes equal to 0.5.
The outer loop begins at offset one, deliberately excluding the current bar. For each evaluated offset i, its preceding midpoint is located at i+1. The largest referenced offset is therefore Period+1. Set the study's maximum bars back manually to at least that number before running the indicator and revise it whenever Period changes. With the default period of twenty, the requirement is twenty-one historical offsets. The script assumes sufficient history has been established by the platform's study settings; it does not implement an independent history-count guard.
The direct loop recomputes the complete sample on each calculation. This costs time proportional to Period but avoids maintaining mutable rolling counts across callbacks. With identical input data it returns identical results when recalculated. A rolling implementation could improve performance, provided it preserves the exact deadband boundaries and correctly handles history resets and repeated updates. The sample returns without setting plots when invalid parameters or invalid price intervals are encountered; this is not an explicit missing-value buffer, so inspect platform plot behavior if malformed data are possible.
Installation and confirmation timing
Open the PowerLanguage .NET Editor, create an Indicator study named PSMidpointMigration, and replace its user source with the example. Build the study and resolve diagnostics in the installed version before applying it to a chart. Configure the maximum bars back and select a separate subchart so the percentage and percentage-point outputs do not share the price scale. Set Period to five to reproduce the worked sample. Inspect the individual values in the chart's data display. The source has not been compiled or executed in MultiCharts .NET here.
All price references use positive offsets, so the active candle's own high and low do not enter the statistic. The confirmed result is intentionally displayed on the bar after the newest evaluated observation. If the platform calculates intrabar, that completed sample can be available as the next candle begins; otherwise the configured study update schedule determines visibility. No future observations are accessed. Completed values do not intentionally repaint under unchanged history, although data corrections, different session templates or chart reconstruction may legitimately change them.
Testing and limitations
Reproduce both deadband examples, then test all-up, all-down, flat and alternating midpoint sequences. Verify exact boundary equality, Period equal to one and the maximum historical offset. Compare historical values with replay calculations on identical data. Because the metric counts directions rather than sizes, a small qualifying advance contributes as much as a very large one. It ignores the price path within candles, trading volume, liquidity and execution costs. Midpoint direction is not candle body direction or aggressive order flow. Overlapping samples are statistically dependent. Evaluate any proposed downstream rule independently across market conditions and include realistic spreads, commissions and slippage.
For tick-based deadbands, weighted migration scores, alerts or integration into other .NET studies, contact our Custom MultiCharts .NET indicator Development Services.
Risk disclosure: educational material only. Trading involves risk of loss. Hypothetical examples do not establish profitability.