Advanced Trading Tutorial — MultiCharts .NET C# indicator development

Closing prices receive considerable attention in technical analysis, yet a candle's entire high-low interval can migrate in a different direction from its closing price. A close near the bottom of a rising price interval may still belong to a market whose observed range center is moving upward. Candle Midpoint Migration is a signed path-efficiency statistic designed to examine that particular property. It compares the net displacement of successive high-low midpoints with the total distance traveled by those midpoints. Unlike an ordinary close-based momentum measure, its source series is the geometric center of each candle's observed price range. This article implements the measurement in native PowerLanguage .NET C# without placing orders or using future price data.

Specify the source series and the calculation window

Define each candle's midpoint as its low plus half its high-low range. This is equivalent to adding the high and low and dividing by two, but the difference-based expression avoids summing two large absolute price levels unnecessarily. The midpoint is not a volume-weighted average, the price at the middle of the session, or an estimate of fair value. It simply describes the center of the observed high-low interval.

Use N successive midpoint changes calculated from N+1 completed candles. For each adjacent pair, subtract the older midpoint from the newer midpoint. Add the signed changes to obtain net displacement. Separately add the absolute changes to obtain the total midpoint path length. If path length is positive, divide the net displacement by that length and multiply by 100. Because the magnitude of a sum cannot exceed the sum of magnitudes, the result lies between negative one hundred and positive one hundred. The code also clamps tiny numerical excursions outside these bounds.

A reading of +100 indicates that every nonzero midpoint change in the window is upward. A reading of -100 indicates that all nonzero changes are downward. A zero reading can arise from a perfectly flat midpoint series or from positive and negative movements that cancel. The implementation intentionally uses zero for a window with no movement, avoiding division by zero. If distinguishing these two types of zero is important, a separate path-length output can be added. The default period is twenty changes, with the effective input bounded to integers from two through five hundred.

A quantitative example

Suppose five hypothetical completed candle midpoints, ordered from oldest to newest, are 100, 102, 101, 104 and 102. The successive changes are +2, -1, +3 and -2. The net displacement is +2, while the total distance is 2+1+3+2=8. The signed migration score is 100 times 2 divided by 8, or +25. A large part of the movement cancels, even though the final midpoint is above the initial one.

Candle Midpoint Migration Indicator: Signed Efficiency of Range Center Movement
Positive changes are green and negative changes red. Four adjacent midpoint changes create a net displacement of +2 and total path length of 8, giving +25%.

Contrast this path with five midpoints 100, 100.5, 101, 101.5 and 102. The net displacement is still +2, but the total path length is also 2, resulting in +100. The two paths end at the same level and have different migration scores. Reverse the order of either sequence and its score changes sign without changing its absolute magnitude. These hypothetical values establish the mathematical behavior rather than demonstrate trading performance.

Complete PowerLanguage .NET C# indicator

using System;
using System.Drawing;
using PowerLanguage;

namespace PowerLanguage.Indicator
{
    public class CandleMidpointMigration : IndicatorObject
    {
        private IPlotObject scorePlot;
        private IPlotObject zeroPlot;

        public CandleMidpointMigration(object ctx) : base(ctx)
        {
            Length = 20;
        }

        [Input]
        public int Length { get; set; }

        protected override void Create()
        {
            scorePlot = AddPlot(new PlotAttributes("Migration",
                EPlotShapes.Line, Color.RoyalBlue));
            zeroPlot = AddPlot(new PlotAttributes("Zero",
                EPlotShapes.Line, Color.Gray));
        }

        private double Mid(int barsAgo)
        {
            double low = Bars.Low[barsAgo];
            return low + (Bars.High[barsAgo] - low) / 2.0;
        }

        protected override void CalcBar()
        {
            // Always exclude the forming bar.
            int n = Math.Max(2, Math.Min(500, Length));
            double net = 0.0;
            double path = 0.0;

            for (int i = n; i >= 1; i--)
            {
                double d = Mid(i) - Mid(i + 1);
                net += d;
                path += Math.Abs(d);
            }

            double score = path > 0.0 ? 100.0 * net / path : 0.0;
            scorePlot.Set(0, Math.Max(-100.0, Math.Min(100.0, score)));
            zeroPlot.Set(0, 0.0);
        }
    }
}

Installation and study configuration

Open PowerLanguage .NET Editor, create a C# Indicator named CandleMidpointMigration, and replace the generated class with the supplied listing. Compile it, then insert the study into a chart in a separate subchart. The blue line displays the signed score and the gray line displays zero. Set the historical bars-back requirement manually to at least the effective Length plus two bars, counting the current bar, before running the study. For example, Length 20 requires access through index 21, so reserve at least 22 bars. Setting a larger fixed reserve is convenient when experimenting with input values; it also delays the earliest output. Revisit that setting whenever the period increases. The implementation uses the documented IndicatorObject lifecycle, Create, CalcBar, indexed Bars data and IPlotObject.Set methods. Local compilation has not been performed here.

Completed-bar alignment and realtime execution

The loop reads midpoint indices one through N+1, never index zero. As a result, the value plotted at the current bar describes the immediately preceding completed-bar window. This is an explicit alignment choice. If the study runs on every tick, the result should remain stable throughout the forming bar, assuming unchanged earlier data. If the study is configured to run only at bar close, the output still excludes that bar and therefore has a deliberate one-bar delay. Use the update-on-every-tick setting if the previous completed window needs to become visible when a new bar starts. The score is recalculated directly rather than accumulated in mutable state, so repeated calls for the same bar do not double-count movement.

The historical plot requires no future observations, centered window or negative bars-ago references. However, price-history corrections, session configuration, and chart reconstruction may change candle highs and lows. These are changes in the input dataset, not intentional lookahead. When comparing live and historical outputs, first check timestamp alignment and the configured bars-back requirement.

Parameter tradeoffs

A short window responds quickly to changes in range-center direction but can reach extreme readings based on only a few observations. A longer period may provide a broader perspective while retaining old opposing movements for longer. The default twenty is an illustrative research setting, not an optimized universal parameter. Flat midpoint changes contribute zero to both sums and do not dilute the ratio directly. Consequently, a window containing just one nonzero positive change can score +100. An independent minimum-path or activity filter can help distinguish sparse movement from a sustained sequence. Such a filter is not included in this listing.

Validation checklist

  • Use a short period of four and reproduce the +25 example from exported highs and lows.
  • Verify monotonic rising and falling midpoint sequences produce +100 and -100.
  • Test a flat sequence and a nonflat path returning to its initial midpoint; both should score zero.
  • Scale all prices by a positive constant or add a constant to each price and check invariance within floating-point tolerance.
  • Verify adequate bars-back configuration and inspect the intentional one-bar alignment.
  • Observe multiple ticks of the newest bar and confirm the completed-window score remains stable.

Limitations and customization

Midpoint efficiency describes movement of range centers, not actual intrabar travel or a tradeable execution path. A single extreme print can move the midpoint even when most trades occur elsewhere. The ratio also discards absolute path size: very small changes can be as efficient as large changes. It does not account for spread, commissions, liquidity or market impact. If you are interested in adding a path-length filter, a session reset, or an integration into an existing signal, contact us through our Custom MultiCharts .NET indicator Development Services.

Trading involves risk of loss. The examples are hypothetical, the code requires local testing, and no indicator reading establishes future returns or a profitable trading strategy.

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.