Intermediate Trading Tutorial — Confirmed Rolling Range Close Location in Sierra Chart

A closing price by itself does not tell us where the market finished relative to its recent trading range. A close of 108 might be near the top of one window and near the bottom of another. This tutorial builds a native ACSIL study that converts the latest completed close into a centered, dimensionless location score. Unlike a single-candle close location calculation, the reference is the entire rolling window of completed candles. The score describes location, not the probability of a future price move.

Define the reference window

For a displayed bar with chronological index t, take the N bars from t minus N through t minus one. Compute H as the highest high and L as the lowest low across those bars. C is the close of the last completed bar. The location score is 2 multiplied by (C minus L) divided by (H minus L), minus one. For consistent OHLC data and a positive range width, the score lies between minus one and plus one. At the lower boundary it equals minus one, at the midpoint it equals zero, and at the upper boundary it equals plus one. Equivalently, divide the closing price's displacement from the range midpoint by half the range width.

The reference includes the completed candle whose close is evaluated. Consequently, this is a location statistic rather than a prior-range breakout distance indicator. That distinction matters: a new extreme may expand the reference window and move its midpoint, but it cannot produce a valid location beyond the mathematical bounds. An indicator designed to measure breakouts would instead exclude the evaluated candle from its reference window.

Confirmed Rolling Range Close Location Indicator
Three independent hypothetical windows share a high of 110 and a low of 100. Closing prices of 108, 105 and 102 produce centered location scores of +0.6, 0 and −0.6 respectively.

Manual examples

Consider a three-bar sample with highs of 107, 110 and 109, lows of 100, 103 and 104, and a final close of 108. Its range is ten price units. The score is 2 × (108−100)/10−1 = +0.6. The close is 80% of the way from the low to the high, which corresponds to +0.6 on the centered scale. For independent windows with the same extrema and closes of 105 and 102, the scores are zero and −0.6. If a window has a high and low both equal to 100, there is no meaningful location ratio. The code marks the calculation invalid rather than treating it as evidence of balanced trading.

When a new bar appears, the oldest bar leaves the reference and the newly completed bar enters it. If the outgoing bar supplied the highest high or lowest low, the reference can change even when the latest close remains unchanged. This is an expected property of rolling extrema rather than a defect. The study measures the location of price relative to a changing reference, not the direction of every individual price change.

Complete native ACSIL source

#include "sierrachart.h"

SCDLLName("PatternSmart Range Close Location")

SCSFExport scsf_PSConfirmedRangeCloseLocation(SCStudyInterfaceRef sc)
{
    SCSubgraphRef Score = sc.Subgraph[0];
    SCSubgraphRef Valid = sc.Subgraph[1];
    SCInputRef Length = sc.Input[0];

    if (sc.SetDefaults)
    {
        sc.GraphName = "PS Confirmed Range Close Location";
        sc.StudyDescription = "Previous closed window location";
        sc.AutoLoop = 1;
        sc.GraphRegion = 1;

        Score.Name = "Location";
        Score.DrawStyle = DRAWSTYLE_LINE;
        Score.PrimaryColor = RGB(45, 105, 190);
        Score.LineWidth = 2;
        Score.DrawZeros = 1;

        Valid.Name = "Valid";
        Valid.DrawStyle = DRAWSTYLE_IGNORE;

        Length.Name = "Window Length";
        Length.SetInt(20);
        Length.SetIntLimits(1, 10000);
        return;
    }

    const int n = Length.GetInt();
    const int t = sc.Index;
    sc.DataStartIndex = n;

    // Use only bars before the displayed bar.
    Score[t] = 0.0f;
    Valid[t] = 0.0f;
    if (t < n)
        return;

    const int last = t - 1;
    const int first = t - n;
    double hi = sc.High[first];
    double lo = sc.Low[first];

    for (int j = first + 1; j <= last; ++j)
    {
        if (sc.High[j] > hi)
            hi = sc.High[j];
        if (sc.Low[j] < lo)
            lo = sc.Low[j];
    }

    const double width = hi - lo;
    const double c = sc.Close[last];
    // Reject flat windows and inconsistent closing prices.
    if (!(width > 0.0) || !(c >= lo && c <= hi))
        return;

    Score[t] = (float)(2.0 * (c - lo) / width - 1.0);
    Valid[t] = 1.0f;
}

Understanding the implementation

The SetDefaults branch configures a separate chart region, an automatically looped study, an adjustable integer input and two subgraphs. The visible subgraph contains the location score. The second subgraph provides a validity flag and uses an ignored drawing style. A value of one in the flag indicates a valid observation. A zero indicates insufficient history, a flat range or inconsistent input. The displayed score uses zero as a fallback for invalid data; therefore a downstream study must check the validity flag before interpreting a zero score as an actual midpoint reading.

DataStartIndex is assigned to N. The earliest eligible displayed bar has index N because its preceding N bars must exist. The source initializes the high and low from the oldest eligible bar, then examines each remaining observation through index t minus one. This approach avoids any dependence on the active bar's high, low or close. It performs a direct linear scan per evaluation, which makes the indexing easy to inspect. Its cost grows with the selected period; specialized rolling extrema structures may improve performance for very large windows, but must handle chart recalculations and historical revisions correctly.

Installation and configuration

Save the source as a C++ file in the Sierra Chart ACS_Source directory. Open the Advanced Custom Study DLL build interface under the Analysis menu, select the source, and use an available build method. After a successful build, open the chart studies dialog and add the custom study by its name. Set Window Length to three for the manual example, or use a suitable research period. Check the output values and validity subgraph when linking the study to another calculation. The source has not been compiled or executed in Sierra Chart here; confirm compatibility in your installed version.

Closed-bar behavior and repainting

The study deliberately plots the result on the bar following the evaluated window. On a forming bar, its own price updates do not enter the calculation. Once a new bar appears, the preceding completed close becomes eligible. This one-bar display alignment is intentional and should not be shifted backward in a way that implies earlier availability. Under unchanged historical data, the formula does not intentionally repaint or reference future prices. Feed corrections, changes in session settings and chart rebuilding may legitimately change historical inputs. If the market closes without creating another bar, the most recent candle may not yet be reflected in a new displayed reading.

Validation and limitations

Test the worked sample in a spreadsheet, then examine windows ending exactly at their highs, lows and midpoints. Check flat windows and insufficient history. Confirm that the result remains unchanged while the displayed candle forms, provided completed data are unchanged. Compare replay and historical values using identical chart settings. The score does not measure the magnitude of the range, the order of intrabar events, traded volume or liquidity. A high score can accompany either a tiny or a large move; it is not proof of trend continuation or a reversal. Thresholds require independent evaluation, including realistic trading costs and differences between market regimes.

For alerts, session-specific windows, volatility filters or integration with other ACSIL studies, contact our Custom Sierra Chart indicator Development Services.

Risk disclosure: educational material only. Trading involves risk of loss. Hypothetical examples 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.