Advanced Trading Tutorial — Close Location Persistence in cTrader

A candle can close near its high even when the market is falling from one bar to the next. Conversely, a rising market can contain candles that finish near their lows. Close location and directional momentum describe different properties of price. This tutorial develops a bounded oscillator that summarizes where a sequence of completed candles closes within their individual ranges. It is intended as a research tool rather than an automatic trading signal.

Mathematical definition

For each candle calculate (2 × Close − High − Low)/(High − Low). A close at the high gives +1, a close at the low gives −1, and a close at the midpoint gives zero. A candle with zero range contributes zero. Average the scores over N completed candles with equal weights. Equal weighting prevents a single exceptionally wide candle from automatically dominating the result, although it also means that a narrow candle receives the same weight as a wide one.

Close Location Persistence Indicator
Three hypothetical closed-bar scores of +0.8, +0.6 and −0.2 produce an average of +0.4.

Worked example

Assume each of three independent candles has a high of 110 and a low of 100. Their closes are 109, 108 and 104. The corresponding scores are +0.8, +0.6 and −0.2. Their sum is 1.2 and the three-bar average is +0.4. The indicator does not require the open price, and the example does not imply that the candles form an upward trend. A positive average simply describes a tendency to finish in the upper portion of the observed ranges.

Native cTrader C# indicator

The implementation uses the cAlgo.API namespace, an IndicatorDataSeries output and the Bars collection. cTrader invokes Calculate with a chronological index, unlike platforms that use zero as the most recent bar. The loop therefore visits index minus Period through index minus one. This deliberately excludes the bar at the current calculation index, both historically and in live operation.

using cAlgo.API;
namespace cAlgo
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class CloseLocationPersistence : Indicator
    {
        [Parameter("Period", DefaultValue = 10, MinValue = 1)]
        public int Period { get; set; }

        [Output("Persistence", LineColor = "DodgerBlue")]
        public IndicatorDataSeries Result { get; set; }

        public override void Calculate(int index)
        {
            // Plot at the next bar: all inputs are already closed.
            if (index < Period)
            {
                Result[index] = double.NaN;
                return;
            }
            double sum = 0;
            for (int j = index - Period; j < index; j++)
            {
                double h = Bars.HighPrices[j];
                double l = Bars.LowPrices[j];
                double c = Bars.ClosePrices[j];
                double range = h - l;
                // Treat a zero-range candle as neutral.
                if (range > 0)
                    sum += (2 * c - h - l) / range;
            }
            Result[index] = sum / Period;
        }
    }
}

Timing and repainting

The value plotted at bar t summarizes the N completed bars ending at t−1. This explicit one-bar alignment makes the value available when the new bar is recognized, and it remains stable during ordinary ticks of that bar. It is not a centered average and does not reference future data. Historical revisions, changes to the chart's bar construction or a different data feed can still change results. When comparing this oscillator to another indicator, account for the fact that the plotted timestamp represents the availability of the information, not the timestamp of the final input candle.

Installation

Open cTrader Algo, create a new C# indicator named CloseLocationPersistence, replace the generated class with the source above and build. Add it to a chart from the indicator menu. Start with Period=10, then use Period=3 to reproduce the worked example. The initial N bars are assigned NaN rather than a fabricated neutral reading. The implementation uses no external libraries or network access.

Research workflow and limitations

Test a sequence of closes at the high, a sequence at the low, midpoint closes and zero-range candles. Check that a live forming bar does not alter its displayed result. Compare different timeframes and instruments using the same interpretation of the output. A persistent positive value may describe sustained upper-range closes, but it cannot establish whether actual buying volume is dominant. OHLC data do not reveal the sequence of transactions inside a candle. A declining market can still produce positive readings. Consider combining the measure with independent trend and volatility context when designing research hypotheses. The direct loop costs O(N) per calculation; a rolling sum may be appropriate for unusually large windows. No compilation or live execution has been performed here.

For alerts, weighted variants or cBot integration, contact our Custom cTrader indicator Development Services.

Risk disclosure: educational use only. Trading involves risk of loss. Hypothetical calculations do not establish profitability.

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.