- Extended Parabolic SAR with **asymmetric acceleration factors** for long and short positions.
- Sign-encoded output: positive = long (SAR below price), negative = short (SAR above price).
- Matches TA-Lib `TA_SAREXT` specification with 8 parameters.
- Auto-detects initial direction from Directional Movement when `startValue == 0`.
- Validated against TA-Lib reference implementation.
## Introduction
The Parabolic SAR Extended (SAREXT) is an enhanced version of Wilder's Parabolic Stop And Reverse that allows **separate acceleration factor configurations for long and short positions**. While standard PSAR uses the same AF start, increment, and maximum for both trend directions, SAREXT provides six independent AF parameters (three for long, three for short), plus a `startValue` to force initial direction and `offsetOnReverse` to add a gap buffer when the indicator reverses.
This design makes SAREXT suitable for markets where bullish and bearish trends have different characteristics — for example, equity markets where rallies tend to be gradual (lower AF) and selloffs tend to be sharp (higher AF).
## Historical Context
SAREXT originates from the TA-Lib open-source technical analysis library, where it appears as `TA_SAREXT`. It extends Wilder's original 1978 PSAR with asymmetric parameters, addressing a common criticism: that markets don't behave symmetrically in both directions. The TA-Lib implementation adds the `startValue` parameter for deterministic initialization (useful in backtesting) and `offsetOnReverse` for creating a buffer zone that reduces whipsaw on reversals.
## Architecture and Physics
### 1. State Machine
SAREXT operates as a two-state machine identical to PSAR: **Long** (uptrend) and **Short** (downtrend). Each state tracks:
- **SAR**: Current stop level
- **EP** (Extreme Point): Highest high in long mode, lowest low in short mode
| Warmup | 2 bars | Bar 0 collects data, bar 1 determines direction |
### SIMD Analysis
SAREXT cannot be vectorized. The state machine has data-dependent branches (reversal detection, direction-specific AF selection) and sequential dependencies. The Batch API delegates to streaming for correctness.
### Quality Metrics (1–10 Scale)
| Metric | Score | Rationale |
|--------|-------|-----------|
| Trend detection | 7 | Same as PSAR; asymmetric AF can reduce false reversals |
| Responsiveness | 9 | Independent AF tuning per direction improves adaptability |
| False signals | 6 | offsetOnReverse helps reduce whipsaw vs standard PSAR |
| TA-Lib | ✅ | 1e-8 | `Functions.SarExt(highs, lows, ...)` with all 8 parameters |
| Self | ✅ | 1e-10 | Streaming == Batch == Span |
## Common Pitfalls
1.**Sign interpretation**: Output is sign-encoded. Use `Math.Abs(output)` for the raw SAR level. Check `output > 0` for long, `output < 0` for short.
2.**Bar 0 outputs NaN**: The first bar collects data only. Valid output starts at bar 1 (sample index 2).
3.**offsetOnReverse too large**: Large offsets create SAR values far from price, delaying re-entry. Start with 0 and increase incrementally.
4.**Asymmetric AF interaction**: Setting `afMaxShort` much higher than `afMaxLong` makes short-side SAR track price tightly while long-side SAR lags. This is intentional for bearish-bias strategies but may surprise.
5.**Auto-detect sensitivity**: When `startValue == 0`, the DM comparison on bars 0–1 determines initial direction. A single bar's DM can be noisy; use `startValue` for deterministic behavior in backtests.
6.**No SIMD path**: Sequential state machine with data-dependent branches prevents vectorization. Batch API is O(n) sequential.
## References
- TA-Lib. "TA_SAREXT — SAR Extended." Open-source technical analysis library.
- Wilder, J. W. Jr. (1978). *New Concepts in Technical Trading Systems*. Trend Research. ISBN 978-0894590276.