Beginner Trading Tutorial | ACSIL

A price gap is the difference between the opening price of a bar and the closing price of its immediate predecessor. Expressing that difference as a percentage makes it easier to compare instruments with different price levels. This tutorial builds a small Sierra Chart study that displays the signed gap percentage only after the bar has closed. It is a descriptive indicator, not an entry system.

Calculation and examples

Gap % = 100 × (current open − previous close) / previous close. With a previous close of 100, an opening price of 102 produces +2%, 99 produces −1%, and 100 produces 0%. These are three independent hypothetical cases, not successive bars. A positive reading identifies an opening above the preceding close; it does not imply that the price subsequently rose. The current bar might close below its open despite a positive gap.

Confirmed Gap Percent Indicator in ACSIL

Three hypothetical openings relative to the same reference close of 100.

Percentage normalization is useful when comparing a $20 stock with a $200 stock. A one-dollar difference is 5% in the first case and 0.5% in the second. It does not normalize volatility, liquidity or trading costs. For those purposes, additional measures would be necessary.

Complete ACSIL source

#include "sierrachart.h"
SCDLLName("PatternSmart Confirmed Gap Percent")

SCSFExport scsf_ConfirmedGapPercent(SCStudyInterfaceRef sc)
{
    SCSubgraphRef Gap = sc.Subgraph[0];
    if (sc.SetDefaults)
    {
        sc.GraphName = "Confirmed Gap Percent";
        sc.AutoLoop = 1;
        sc.GraphRegion = 1;
        Gap.Name = "Gap %";
        Gap.DrawStyle = DRAWSTYLE_BAR;
        Gap.PrimaryColor = RGB(32,135,103);
        Gap.SecondaryColor = RGB(190,69,70);
        Gap.SecondaryColorUsed = 1;
        Gap.DrawZeros = 0;
        return;
    }
    // Clear the live bar and the first bar.
    Gap[sc.Index] = 0;
    if (sc.Index < 1 ||
        sc.GetBarHasClosedStatus() != BHCS_BAR_HAS_CLOSED)
        return;
    // Use the immediately preceding close.
    float prev = sc.Close[sc.Index - 1];
    if (prev <= 0)
        return;
    float value = 100.0f * (sc.Open[sc.Index] - prev) / prev;
    Gap[sc.Index] = value;
    Gap.DataColor[sc.Index] = value < 0 ?
        Gap.SecondaryColor : Gap.PrimaryColor;
}

Implementation details

The study uses AutoLoop so Sierra Chart supplies the index for each calculation. GraphRegion 1 places the histogram in a separate region, avoiding interference with the price scale. The subgraph stores a single signed value per bar. DataColor assigns green to positive values and red to negative values. DrawZeros is disabled, so the first bar, the unfinished bar, invalid reference prices and genuine zero gaps all appear blank. A downstream study must not interpret every zero as a confirmed observation.

The first available bar has no preceding close. The index guard prevents reading outside the array. The denominator guard excludes zero and negative reference prices; this definition is intended for instruments with positive prices. A negative price contract would require a different normalization convention. The explicit reset prevents an old value remaining visible when a bar is recalculated.

Closed-bar behavior and repainting

The opening price is usually established at the first trade of a bar, but the example deliberately waits for Sierra Chart to report that the bar is closed. The final bar may remain unconfirmed until another bar is created. The histogram is placed on the completed bar, not on the following bar, so historical inspection must not mistake the plotted location for an earlier actionable signal. No future price is used in the formula. Under unchanged historical data and chart settings, completed values should remain stable. Corrections to the feed, changed session definitions, contract adjustments and reconstructed bars can change historical values.

Installation

Open Sierra Chart's ACSIL source folder and save the code as ConfirmedGapPercent.cpp. Use Analysis > Build Custom Studies DLL, select the source and build using the available remote or local compiler. After a successful build, open Analysis > Studies and Add Custom Study, then select Confirmed Gap Percent from the PatternSmart DLL. Apply the study to a chart with sufficient historical bars. Check the message log if compilation fails. The source has not been compiled or run for this tutorial; verify compatibility with your installed Sierra Chart version.

Practical interpretation

On a daily chart the gap describes the difference between consecutive daily bars under the selected session template. On a five-minute chart it measures adjacent five-minute bars, not necessarily overnight gaps. A continuous futures chart may include contract-roll adjustments. A chart with extended hours enabled may produce a different reference close from a regular-session chart. Decide which session definition matches your research before comparing results.

For example, a researcher could group confirmed positive gaps above 1% and compare their subsequent returns with smaller gaps. Define the observation time as the first update after the signal bar closes, not its opening time. Use an independent sample to evaluate the chosen threshold. A large gap can reflect news, thin trading or an adjustment rather than a repeatable opportunity. This indicator does not distinguish those causes.

Testing checklist

Start with the three numerical cases in the illustration. Check a zero-gap bar, the first loaded bar and a bar that is still forming. In Chart Replay, observe the blank live bar and confirm that the histogram appears on the completed bar after the next bar begins. Compare several values with the chart's open and previous close using a calculator. Reload the chart and compare the same timestamps. Repeat with different session templates and document any changes. Check both positive and negative readings and verify the displayed scale is percentage points rather than raw price units.

For further customization, such as a session-opening-only version or a separate validity output for automated consumers, see Custom Sierra Chart indicator Development Services.

Limitations and risk

This study does not measure intrabar direction, volume, spread or the likelihood of a gap filling. It does not issue orders or account for commissions, slippage or execution delays. Hypothetical examples are educational, not evidence of profitability. Trading involves risk of loss; test independently before using any indicator in live decisions.

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.