fintech-algorithms

Parabolic SAR

Audit the Stop, Extreme Point, and Acceleration Factor

Install and import

bash
npm install fintech-algorithms
ts
import { 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

NameTypeNotes
highnumber[]Per-bar high prices, chronological.
lownumber[]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.
accelerationStepnumberIncrement added to the acceleration factor each time a new extreme is made.
min: 0
accelerationMaxnumberCeiling 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

high
[117.555, 118.215368, 118.945956, 119.686391, 120.381031, 120.987562]

Showing 6 of 180 elements.

low
[115.1985, 115.34324, 115.864377, 116.536001, 117.321542, 118.15831]

Showing 6 of 180 elements.

initialDirection
"long"
accelerationStep
0.02
accelerationMax
0.2

Call

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

Parabolic SAR — canonical trace
Parabolic SAR — failure boundary
Parabolic SAR — mechanism map

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.

Read the article →

References