TradingView indicator calculations

Accumulative Swing Index on TradingView: SI, ASI and scaling

The Accumulative Swing Index (ASI) adds each bar's Swing Index (SI) to a running total. SI compares current OHLC prices with the previous open and close; its limit-move input sets the scale. To compare TradingView implementations, match that input, the formula, rounding and starting history. A cumulative reading above zero alone does not establish a trade.

See the decision guide

Calculate the Swing Index before accumulating it

This page uses the absolute-distance formula documented by TA-Lib. Let O, H, L and C be the current bar prices, and Op and Cp the previous open and close. Set a = abs(H - Cp), b = abs(L - Cp), d = abs(H - L), q = 0.25 × abs(Cp - Op), K = max(a, b), and N = (C - Cp) + 0.5 × (C - O) + 0.25 × (Cp - Op). The signed term in N differs from the absolute term in q.

  • For positive limit move T, SI = 50 × (N / R) × (K / T). This implementation returns SI = 0 when R = 0, and does not clamp the result.
  • Seed ASI at zero on the first valid bar, then ASI[t] = ASI[t-1] + SI[t]. Keep unrounded values in the sum; round only their display.
Branch, evaluated in orderDenominator R
a ≥ b and a ≥ da - 0.5 × b + q
Otherwise, b ≥ db - 0.5 × a + q
Otherwised + q

A four-bar example with a gap

These invented prices use T = 10 price units. Bar 0 anchors ASI at zero. All displayed results are rounded to four decimals, but the running calculation retains full precision. No volume data enters the formula.

  • Bar 1: a = 4, b = 1, d = 5, q = 0.5, so R = 5.5. SI = 50 × (5 / 5.5) × (4 / 10) = 18.181818.
  • Bar 2: the previous body contributes +0.75 to N, although the current close falls. SI = 50 × (-5.25 / 6.75) × (5 / 10) = -19.444444. ASI becomes -1.262626.
  • Bar 3 gaps above the previous close of 101. With a = 9, b = 6, d = 3 and q = 1, the first branch gives R = 9 - 3 + 1 = 7. Using only the intrabar range of 3 would produce a different answer.
  • A separate downward-gap check uses previous O = 105, C = 101 and current O/H/L/C = 95/97/93/94. Here b = 8 is largest, R = 8 - 2 + 1 = 7 and SI = -48.571429 at T = 10.
BarO / H / L / CN / R / KSIASI
0100 / 103 / 99 / 102AnchorUnavailable0.0000
1102 / 106 / 101 / 1055 / 5.5 / 418.181818.1818
2105 / 106 / 100 / 101-5.25 / 6.75 / 5-19.4444-1.2626
3108 / 110 / 107 / 1097.5 / 7 / 948.214346.9517

Limit move means scaling, not clipping

Use the same unit for T as for the chart prices. If a price tick is 0.25 and the specified move is 40 ticks, enter 10 price units, not 40. The example is a unit conversion, not a claim about any contract's exchange limit. For a market or interval without an applicable fixed limit, document the chosen positive normalization value.

  • Changing a constant T from 10 to 20 halves every SI and ASI value: the last ASI above becomes 23.4758. With the same anchor, consistently rescaled trendlines retain their crossing times; fixed numeric thresholds must also be rescaled.
  • Changing T from 10 to 1 makes bar 3 SI equal 482.1429. The formula has no hard ±100 cap when the chosen scale does not bound the moves. Clipping to ±100 would change ASI.
  • A time-varying T changes the weighting of different bars, not merely the axis scale. Do not compare that variant with a constant-T implementation as if they were identical.
  • Daily-session limits do not automatically define an intraday-bar scale. Keep the timeframe and your normalization convention in the comparison record.

Initialization and missing values change the comparison

The example below anchors the first valid OHLC bar at zero. It requires two consecutive valid bars to calculate SI. An invalid bar makes ASI unavailable; the next valid bar starts a new segment at zero. This reset policy is explicit and may differ from another script's missing-value policy.

  • The first bar cannot supply a previous open and close. Replacing those missing prices with zero would invent a large swing.
  • A completely flat pair with both bars at 100 gives R = 0 and SI = 0 under this convention. A bar with high = low is not necessarily a flat pair if it gaps from the previous close.
  • For a shared continuous price history and constant T, starting earlier changes the ASI baseline by the omitted accumulated SI. Compare changes or rebase both lines at the same timestamp before comparing levels.
  • A market closure without a chart bar is not an explicit missing-valued bar. The next available bar still compares with the previous available bar and can include a price gap.

Inspect SI and ASI together in Pine Script v6

Paste this calculation into Pine Editor. It plots ASI as a line and the swing index indicator as a histogram, with N, R and K in the Data Window. It implements the formula and reset policy above, without trade signals or order execution.

  • Compare completed bars on the same symbol, exchange, standard OHLC chart, timeframe and session. The invented fixture is a separate arithmetic check; ordinary chart data will have different values.
  • Check the selected TradingView script's author, source and inputs. An ASI title alone does not establish its tie handling, absolute-value choices, rounding or cumulative seed.
  • The current bar's OHLC and indicator values develop before close. Syntax checking does not establish numerical agreement with a particular TradingView script or feed.
An inspectable calculation with positive-T validation, zero-denominator handling and explicit segment resets.pine
//@version=6
indicator("SI and ASI calculation audit", overlay = false)
limitMove = input.float(10.0, "Limit move (price units)", minval = 0.00000001)
validBar = not na(open) and not na(high) and not na(low) and not na(close) and high >= math.max(open, close) and low <= math.min(open, close)
validPair = validBar and validBar[1]
float si = na
float r = na
float k = na
float numerator = na
if validPair
    a = math.abs(high - close[1])
    b = math.abs(low - close[1])
    d = math.abs(high - low)
    q = 0.25 * math.abs(close[1] - open[1])
    r := a >= b and a >= d ? a - 0.5 * b + q : b >= d ? b - 0.5 * a + q : d + q
    k := math.max(a, b)
    numerator := close - close[1] + 0.5 * (close - open) + 0.25 * (close[1] - open[1])
    si := r == 0 ? 0 : 50 * numerator / r * k / limitMove
var float asi = na
if not validBar
    asi := na
else if not validPair
    asi := 0
else
    asi := nz(asi[1]) + si
plot(asi, "ASI", color = color.blue, linewidth = 2, style = plot.style_linebr)
plot(si, "SI", color = color.orange, style = plot.style_histogram)
plot(r, "R", display = display.data_window)
plot(k, "K", display = display.data_window)
plot(numerator, "Numerator", display = display.data_window)
hline(0, "Anchor zero", color = color.gray)

Define a trendline break that can be observed in real time

Use two already confirmed ASI swing highs to define resistance, then extend that line using their bar coordinates. For example, highs of 60 at bar 10 and 50 at bar 20 give a slope of -1 ASI unit per bar and resistance of 47 at bar 23. A completed-bar ASI of 48 is above that line; a current-bar reading of 48 that closes at 46 is not a close-confirmed break.

  • Specify a crossing event: current confirmed ASI is above the current line, and previous ASI was at or below the previous line. Being above resistance for five bars is not five new breakouts.
  • If swing selection needs two bars to the right, the bar-20 high becomes known only at bar 22. Do not backdate a signal to bar 20 when reviewing historical labels.
  • A price-confirmation rule can separately require the price close to exceed its own resistance. Record whether both conditions must occur on the same bar or within a fixed number of bars. ASI and price come from the same OHLC data, so agreement is not independent evidence.
  • Cancel the comparison across a missing-data reset and redraw using one continuous segment. A breakout can still reverse; confirm timing, exits and costs before testing it as a strategy.

Turn the audited rules into a Pineify request

Give the Pine Script AI Coding Agent the formula, T units, unrounded accumulation and missing-data policy. Ask it to preserve the diagnostic plots before adding a chosen pivot rule and chart-bar-close alert. Compare the generated values and signal timestamps in TradingView before extending the script into a strategy.

  • Include the four-bar fixture and the expected final ASI of 46.951659. Specify whether a new confirmed swing replaces the active trendline and when an old line expires.
  • Pineify can draft and revise Pine Script from these requirements. A syntax check does not verify returns, reproduce a protected script or replace a bar-by-bar comparison.
Where Pineify fits

Pine Script AI Coding Agent

Draft an ASI script with explicit scaling and initialization, inspect its values, then add your confirmed signal rule.

Build an ASI audit script

Frequently asked questions

Educational calculations, not investment advice. All price and trendline examples are hypothetical. Indicator agreement and syntax validation do not establish profitable trading.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.