Intermediate Trading Tutorial — Confirmed Signed Price Path Efficiency in cTrader
Two instruments can finish a sequence of candles with identical net price changes while following very different paths. One may move steadily in a single direction, while the other repeatedly reverses before reaching the same destination. A conventional momentum reading based only on the first and last close cannot distinguish these cases. This tutorial develops a native cTrader C# oscillator that divides signed net displacement by the sum of absolute close-to-close changes. The result combines directional information with a measure of how directly the sampled closing prices traveled between their endpoints.
Define the rolling measurement
Choose a positive integer N representing the number of consecutive price changes, not the number of prices. For each completed bar, identify its close and the close N bars earlier. Subtract the earlier price from the later price to calculate signed displacement D. Next sum the absolute difference between each pair of consecutive closes in the same window to obtain total path length P. The signed efficiency is D divided by P when P is positive. By the triangle inequality, the magnitude of displacement cannot exceed total path length, so valid scores lie between minus one and plus one.
A positive reading indicates upward net displacement, while a negative reading indicates downward net displacement. A magnitude near one indicates that the sampled closing prices moved predominantly in one direction. A reading near zero indicates that opposing changes largely canceled or the endpoints were close together relative to the path. This is related to the unsigned efficiency ratio commonly used in adaptive moving averages, but preserves the sign of the net move. It is not a direct estimate of trend probability.

Numerical examples and edge cases
Set Period to three. The first sequence contains closes 100, 101, 102 and 103. Its net displacement is 103 minus 100, or three. The absolute changes are one, one and one, giving a path length of three. The result is +1. In the second sequence, closes are 100, 104, 101 and 103. Its net displacement is also three, but the absolute changes are four, three and two. Total path length is nine, and the result is +0.3333. Thus equal net returns need not imply equal directional efficiency.
Reverse the first sequence to 103, 102, 101 and 100 and the result becomes −1. A sequence of 100, 102, 98 and 100 gives displacement zero and path length eight, so its valid score is zero. A completely flat sequence of four prices equal to 100 instead has a zero denominator. The implementation returns NaN for that case: there is no observed movement against which to measure efficiency. This distinction is useful when a downstream rule differentiates inactivity from active price movement that cancels out. All examples are hypothetical, not observed trading results.
Complete native C# source
using System;
using cAlgo.API;
namespace cAlgo
{
[Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
public class PSSignedPathEfficiency : Indicator
{
[Parameter("Period", DefaultValue = 20,
MinValue = 1, MaxValue = 10000)]
public int Period { get; set; }
[Output("Signed Efficiency", LineColor = "SteelBlue",
Thickness = 2)]
public IndicatorDataSeries Result { get; set; }
public override void Calculate(int index)
{
// Exclude the forming bar; finalize its predecessor.
if (index == Bars.Count - 1)
{
if (index > 0)
CalculateCompleted(index - 1);
Result[index] = double.NaN;
return;
}
CalculateCompleted(index);
}
private void CalculateCompleted(int index)
{
// N price changes require N+1 closing prices.
if (index < Period)
{
Result[index] = double.NaN;
return;
}
double path = 0.0;
int first = index - Period;
for (int j = first + 1; j <= index; j++)
{
double step = Bars.ClosePrices[j] -
Bars.ClosePrices[j - 1];
path += Math.Abs(step);
}
double net = Bars.ClosePrices[index] -
Bars.ClosePrices[first];
if (double.IsNaN(path) || double.IsInfinity(path) ||
double.IsNaN(net) || double.IsInfinity(net) ||
path <= 0.0)
{
Result[index] = double.NaN;
return;
}
// Clamp tiny floating-point overshoots.
Result[index] = Math.Max(-1.0,
Math.Min(1.0, net / path));
}
}
}
Implementation details
The Indicator attribute creates a separate panel and requires no additional access rights. Period is an integer parameter with a default value of twenty and a bounded positive range. The Output attribute defines a numerical series displayed as a line. cTrader passes a chronological bar index into Calculate. Index zero refers to the oldest loaded observation, and Bars.Count minus one identifies the newest bar in the collection.
CalculateCompleted requires index to be at least Period, because N price changes require N+1 prices. The variable first marks the earlier endpoint, while the loop visits each subsequent close through the evaluated index. Each step is converted to an absolute distance before accumulation. Net displacement is calculated separately from the two endpoints. Invalid or nonpositive path lengths produce NaN, and valid results are clamped to the mathematical bounds to guard against small floating-point rounding overshoots.
This implementation directly sums the window each time, so its computational cost is proportional to Period. It is deliberately stateless apart from the output series. Repeated calls for the same completed index with identical input prices produce identical values. A rolling sum can improve performance for long windows, but must correctly remove expired changes and handle historical reloads or duplicate calls. Benchmark such an optimization against the simpler implementation before replacing it.
Installation in cTrader
Open the Algo workspace and create a new C# indicator named PSSignedPathEfficiency. Replace the generated source with the complete example and build it. Inspect compiler diagnostics in your installed version before adding the indicator to a chart. Set Period to three for the worked examples and use the chart's numerical inspection tools to compare the output with independent calculations. The displayed value is dimensionless; it is not a percentage return or a number of pips. The source has not been compiled or executed in cTrader here.
Closed-bar timing and repainting
On the newest chart bar, Calculate explicitly evaluates the preceding completed bar and sets the forming bar's output to double.NaN. Historical completed bars are calculated directly. When the next bar appears, the previous live candle can therefore receive its confirmed result at its own chart index. The value was not available in confirmed form during that candle. A market closure may leave the last bar excluded until another bar is recognized. A cBot or another indicator consuming the result should align its index with the completed observation and reject NaN before comparison.
No future closing prices enter the formula, and completed values do not intentionally repaint under unchanged data. Historical corrections, changes to session definitions, chart reconstruction or different aggregation settings can legitimately change the underlying sequence. For non-time-based bars, separately verify the platform's bar construction and timing. Repeated live updates still recalculate the preceding window, which trades some efficiency for clear and predictable indexing.
Testing and practical limitations
Start with the four worked sequences. Verify the earliest eligible index, Period equal to one, insufficient history and a flat window. Confirm that the newest forming bar stays blank while incoming prices change. During replay, compare the completed reading with a spreadsheet that uses precisely the same N+1 closes. Reload identical chart data and compare historical observations. If you later use thresholds such as +0.6 or −0.6, treat them as research hypotheses, not universally optimal settings.
The score does not measure intrabar excursions, traded volume, spread, liquidity or absolute volatility. A tiny monotonic move can yield +1 just as a large monotonic move can. A low absolute score does not guarantee a breakout, and a high score does not guarantee continuation. Sampling frequency matters because changing the chart timeframe changes the observed path. Evaluate any downstream rule across independent data, different market regimes and realistic execution costs.
For rolling-sum optimization, threshold alerts, volatility filters or cBot integration, contact our Custom cTrader indicator Development Services.
Risk disclosure: educational material only. Trading involves risk of loss. Hypothetical examples do not establish profitability.