Parabolic SAR
Audit the Stop, Extreme Point, and Acceleration Factor
Install and import
npm install fintech-algorithmsimport { parabolic_sar } from "fintech-algorithms/technical-indicators/trend-systems/parabolic-sar";Signature
parabolic_sar(high, low, initialDirection, accelerationStep, accelerationMax)Stop-and-reverse: a trailing stop that accelerates toward price while a trend persists and flips side when price crosses it. Path-dependent — the whole series follows from the initial direction.
Parameters
| Name | Type | Notes |
|---|---|---|
high | number[] | Per-bar high prices, chronological. |
low | number[] | Per-bar low prices, chronological. |
initialDirection | "long" | "short" | Trend direction assumed at the first bar. Because the calculation is recursive, this choice propagates through the entire series. |
accelerationStep | number | Increment added to the acceleration factor each time a new extreme is made. min: 0 |
accelerationMax | number | Ceiling on the acceleration factor. min: 0 |
Returns
Record<string, (number | null)[]> · length same-as-input
Parallel series: sar, trend, extreme_point, acceleration_factor and a reversal flag marking the bars where the stop flipped.
Warm-up
The first 1 positions are null. The first bar establishes the state; the first SAR value applies from the second.
Errors
- When accelerationStep or accelerationMax is negative, or accelerationStep > accelerationMax — throws RangeError
Complexity: time O(n),
space O(n).
Worked example
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input
[117.555, 118.215368, 118.945956, 119.686391, 120.381031, 120.987562]Showing 6 of 180 elements.
[115.1985, 115.34324, 115.864377, 116.536001, 117.321542, 118.15831]Showing 6 of 180 elements.
"long"0.020.2Call
parabolic_sar(high, low, initialDirection, accelerationStep, accelerationMax)Returns
object with 5 fields: sar, trend, extreme_point, acceleration_factor, reversal
{
"sar": [null, 115.1985, 115.1985, 115.34324, 115.60382906, 115.9860052152],
"trend": [null, "long", "long", "long", "long", "long"],
"extreme_point": [null, 118.215368, 118.945956, 119.686391, 120.381031, 120.987562],
"acceleration_factor": [null, 0.02, 0.04, 0.06, 0.08, 0.1],
"reversal": [null, false, false, false, false, false]
}Diagrams
Calculation flow
Parabolic SAR calculation flow
flowchart LR
A["Validated finalized bar"] --> B["Causal window or recursive state"]
B --> C["Explicit seed and boundary rule"]
C --> D["Aligned Parabolic SAR output"]
D --> E["Diagnostics and audit evidence"]
How it works
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References
- J. Welles Wilder, New Concepts in Technical Trading Systems — J. Welles Wilder
- TA-Lib SAR — TA-Lib project or TradingView, as identified by the linked page
- Pinned TA-Lib ta_SAR.c implementation — TA-Lib project or TradingView
- Canonical synthetic fixture and independent arithmetic — The Fintech Builder
- R5 — TA-Lib SAREXT function documentation — TA-Lib project or TradingView