Sierra Chart ACSIL True Range in Ticks: Compare Candle Range with Gap-Aware Volatility

Beginner Trading Tutorial | Sierra Chart | ACSIL C++ custom study

A chart bar can have a relatively narrow high-to-low range even when the market has moved substantially from the preceding close. A common example is a market that reopens at a higher price and then trades within a narrow interval. Looking only at the candle range omits the discontinuity between the previous close and the new interval. True Range provides a practical way to incorporate that missing distance.

In this tutorial we build a complete Sierra Chart ACSIL study that measures both the ordinary bar range and True Range in units of the chart's tick size. A third output reports the extra range attributable to the previous close lying outside the current high-low interval. The study also includes a completed-bar option and a validity flag, making its output suitable for inspection and possible later integration into other studies.

1. Two definitions of price range

Let H and L represent the current bar's high and low, and P represent the preceding bar's close. The conventional candle range is H − L. True Range is the maximum of H − L, the absolute value of H − P, and the absolute value of L − P. An equivalent and often easier-to-visualize expression is TR = max(H, P) − min(L, P). If P already lies inside the current interval, True Range equals the ordinary range. Otherwise True Range extends the interval to include P.

Let q be the positive tick size configured for the chart. Divide each price-unit measurement by q: RangeTicks = (H − L) / q; TrueRangeTicks = TR / q; ExtraTicks = [TR − (H − L)] / q. ExtraTicks is not the open-to-previous-close gap. It measures only the portion by which the previous close extends beyond the current high-low interval. An opening gap that is fully traversed during the bar can therefore result in zero extra ticks.

Sierra Chart ACSIL True Range in Ticks: Compare Candle Range with Gap-Aware Volatility
Figure 1. Hypothetical prices with previous close 100 and tick size 0.25. Each high-low interval is eight ticks, but True Range increases to twelve ticks when the previous close lies outside it.
Previous close High Low Range (ticks) True Range (ticks) Extra (ticks)
100 101 99 8 8 0
100 103 101 8 12 4
100 99 97 8 12 4
100 100 100 0 0 0

All examples are hypothetical. In the second row the current high-low distance is two points, or eight ticks. The previous close is one point below the current low, so the total interval extends from 100 to 103, or twelve ticks. The third row illustrates the symmetric downward case. The extra component is nonnegative and does not communicate the direction of the gap.

2. Complete ACSIL C++ source

// PatternSmart True Range in Ticks - Sierra Chart ACSIL
#include "sierrachart.h"
#include <cmath>

SCDLLName("PatternSmart True Range in Ticks")

SCSFExport scsf_PSTrueRangeInTicks(SCStudyInterfaceRef sc)
{
    SCSubgraphRef RangeTicks = sc.Subgraph[0];
    SCSubgraphRef TrueRangeTicks = sc.Subgraph[1];
    SCSubgraphRef ExtraTicks = sc.Subgraph[2];
    SCSubgraphRef Valid = sc.Subgraph[3];
    SCInputRef ClosedOnly = sc.Input[0];

    if (sc.SetDefaults)
    {
        sc.GraphName = "PS True Range in Ticks";
        sc.StudyDescription = "Compare high-low range and true range in tick units.";
        sc.AutoLoop = 1;
        sc.GraphRegion = 1;
        sc.ValueFormat = 2;
        sc.DataStartIndex = 1;

        RangeTicks.Name = "High-Low (ticks)";
        RangeTicks.DrawStyle = DRAWSTYLE_LINE;
        RangeTicks.PrimaryColor = RGB(55, 99, 191);
        RangeTicks.DrawZeros = false;

        TrueRangeTicks.Name = "True Range (ticks)";
        TrueRangeTicks.DrawStyle = DRAWSTYLE_LINE;
        TrueRangeTicks.PrimaryColor = RGB(22, 130, 105);
        TrueRangeTicks.DrawZeros = false;

        ExtraTicks.Name = "Extra Range (ticks)";
        ExtraTicks.DrawStyle = DRAWSTYLE_BAR;
        ExtraTicks.PrimaryColor = RGB(184, 75, 77);
        ExtraTicks.DrawZeros = false;

        Valid.Name = "Valid (1 or 0)";
        Valid.DrawStyle = DRAWSTYLE_IGNORE;

        ClosedOnly.Name = "Closed Bars Only";
        ClosedOnly.SetYesNo(1);
        return;
    }

    const int i = sc.Index;

    // Clear all outputs before evaluating the current index.
    RangeTicks[i] = 0.0f;
    TrueRangeTicks[i] = 0.0f;
    ExtraTicks[i] = 0.0f;
    Valid[i] = 0.0f;

    // Need a preceding close and a usable chart tick size.
    if (i < 1 || !std::isfinite(sc.TickSize) || sc.TickSize <= 0)
        return;

    if (ClosedOnly.GetYesNo() &&
        sc.GetBarHasClosedStatus() != BHCS_BAR_HAS_CLOSED)
        return;

    const double h = sc.High[i];
    const double l = sc.Low[i];
    const double prev = sc.Close[i - 1];

    if (!std::isfinite(h) || !std::isfinite(l) ||
        !std::isfinite(prev) || h < l)
        return;

    // True range extends the bar interval to include prior close.
    const double top = h > prev ? h : prev;
    const double bottom = l < prev ? l : prev;
    const double range = h - l;
    const double tr = top - bottom;
    const double tick = sc.TickSize;

    RangeTicks[i] = static_cast<float>(range / tick);
    TrueRangeTicks[i] = static_cast<float>(tr / tick);
    ExtraTicks[i] = static_cast<float>((tr - range) / tick);
    Valid[i] = 1.0f;
}

3. How the study interacts with Sierra Chart

ACSIL custom studies use a function exported with SCSFExport and take an SCStudyInterfaceRef argument. The SCDLLName declaration names the custom study library. The sc.SetDefaults branch configures the study rather than performing ordinary bar calculations. We assign a separate graph region, a display precision of two decimal places and three visible subgraphs. The fourth subgraph is an ignored drawing style used to store a validity flag for consumers of the study data.

With sc.AutoLoop set to one, Sierra Chart calls the study function for the bar represented by sc.Index. This is an absolute array index, unlike the bars-ago syntax of several other trading platforms. The preceding close is accessed at index i − 1. The explicit index check avoids relying on boundary correction behavior when the preceding bar does not exist.

The tick-size check uses the chart's sc.TickSize setting. A tick is a configured price increment, not a dollar amount. To estimate the monetary change represented by a number of ticks, a trader would also need the correct contract tick value and position size. This study intentionally does not implement that monetary conversion. It also does not round to an integer: data from adjusted contracts or nonstandard charts can produce fractional tick distances, and retaining them makes data or configuration discrepancies easier to investigate.

4. Completed-bar handling and the hidden validity flag

The Closed Bars Only input defaults to Yes. In this mode, GetBarHasClosedStatus() must report BHCS_BAR_HAS_CLOSED before calculation proceeds. The platform generally treats the last chart bar as not closed until a subsequent bar exists. This means the newest study reading may be withheld even when a scheduled time interval has ended but no new bar has appeared. Disabling this option permits live preview; the high and low may change during the bar, so the latest values remain provisional.

Before evaluating each index, all outputs are cleared to zero. Invalid observations and intentionally suppressed live observations retain Valid = 0. A successfully evaluated bar receives Valid = 1, even when its price range is actually zero. DrawZeros is disabled on the visible subgraphs to avoid misleading lines at uncomputed positions. Consequently, a legitimate zero also does not draw a visible mark. An external study consuming the data should inspect the validity output rather than equating every stored zero with missing data or with a real zero measurement.

5. Parameters and useful experiments

Setting Default Effect
Closed Bars Only Yes Suppress the unfinished chart bar
Chart tick size Chart setting Controls conversion from price units to ticks
Value format 2 decimals Retains fractional tick distances for inspection

There is no lookback period because the calculation compares one bar with one earlier close. This is deliberately a one-bar measurement, not ATR, which smooths True Range over multiple observations. If the research objective is a slowly changing volatility baseline, averaging the valid True Range readings would be a separate extension. The ordinary range and true range can overlap visually when equal; the extra-range bar helps distinguish observations in which the earlier close extends the interval.

6. Build and install in Sierra Chart

  1. Open Analysis → New/Open Custom Studies File and create a file named PSTrueRangeInTicks.cpp in the ACS_Source directory.
  2. Paste the complete source, save it, and use Analysis → Build Custom Studies DLL with the appropriate build method for your installation.
  3. Review the build output and resolve any compiler diagnostics before adding the study.
  4. Open Analysis → Studies, select Add Custom Study, and locate the PatternSmart True Range in Ticks library and study.
  5. Check the chart's tick size in its symbol or chart settings, select the desired bar type, and apply the study.
  6. Use Chart Values or the study data to compare high-low and True Range on a completed bar against a manual calculation.

7. Validation checklist

Begin with a chart whose minimum price increment is known. Find a completed bar in which the previous close is between the current high and low; verify that the two ranges agree. Find a second bar whose previous close lies below the low, and a third whose previous close lies above the high. Check that ExtraTicks equals the difference between the other two outputs, within ordinary floating-point precision. Repeat the test after changing the chart interval. Verify the first loaded observation is not treated as a valid comparison, and confirm the last chart bar is suppressed with Closed Bars Only enabled. When using live preview, compare the value before and after a new extreme forms.

If the values are unexpected, inspect the chart's price scale and tick size first. Data corrections, continuous-contract adjustments and synthetic charts can change the relationship between recorded price distances and the exchange's normal tick increment. A gap caused by contract rollover may not describe a tradable movement in a single contract.

8. Practical uses and limits

This study can help distinguish ordinary intrabar price activity from additional distance relative to the prior close. It may support gap-aware research, volatility filters and debugging of risk calculations expressed in ticks. The True Range measurement is direction-neutral, does not indicate the path taken inside the bar, and does not reveal executable liquidity. A twelve-tick range is not a promise that twelve ticks were available as profit or that a particular stop order would have been filled at its requested price.

Interested in adding session-aware gap classification, ATR in ticks, custom alerts or integration into an automated system? Contact us through our Custom Trading Software Development Services.

The implementation was reviewed against the official ACSIL function and array documentation but has not been compiled or executed in Sierra Chart. Validate it with your own version and data before relying on it. Trading involves risk, and a range measurement cannot guarantee trading results.

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.