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 order | Denominator R |
|---|---|
| a ≥ b and a ≥ d | a - 0.5 × b + q |
| Otherwise, b ≥ d | b - 0.5 × a + q |
| Otherwise | d + q |