Parabolic SAR (Wilder clamp / TA-Lib reference)

Parabolic SAR matching TA-Lib’s reference implementation
TradingView’s built-in ta.sar() omits one of Wilder’s rules: the SAR may not sit inside the current or prior bar’s range. Without that clamp the SAR can land where price has already traded, and the flip arrives a bar late. On SPY daily I found two flips that landed late for this reason.
Wilder left three things open. This script follows TA-Lib on all three:
Seeding — start long unless Wilder’s −DM between bars 0 and 1 exceeds +DM. First SAR is bar 0’s low (long) or high (short). Bar 1 isn’t checked for penetration; bar 2’s SAR is clamped against bar 1 only.
Ties — a low exactly equal to the SAR, or a high equal to it, counts as a reversal.
Reversal SAR — the prior trend’s extreme point, clamped outside the current and prior bar’s range.
Acceleration matches TA-Lib’s SAR(acceleration, maximum): the starting factor and the step are the same number.
Verified by reading the plotted values off the chart against TA-Lib 0.8.1 on SPY daily, 250 bars (2025-08-25 to 2026-08-21): agreement to 1.1e-13, no long/short disagreements, and the SAR never sits inside a bar’s range.
Not verified on-chart: seeding is checked only in the Python model this script follows line for line. With more history loaded than the test window, the first nine bars differ from TA-Lib because the two start on different bars; they agree from there.
MIT license.
TradingView’s built-in ta.sar() omits one of Wilder’s rules: the SAR may not sit inside the current or prior bar’s range. Without that clamp the SAR can land where price has already traded, and the flip arrives a bar late. On SPY daily I found two flips that landed late for this reason.
Wilder left three things open. This script follows TA-Lib on all three:
Seeding — start long unless Wilder’s −DM between bars 0 and 1 exceeds +DM. First SAR is bar 0’s low (long) or high (short). Bar 1 isn’t checked for penetration; bar 2’s SAR is clamped against bar 1 only.
Ties — a low exactly equal to the SAR, or a high equal to it, counts as a reversal.
Reversal SAR — the prior trend’s extreme point, clamped outside the current and prior bar’s range.
Acceleration matches TA-Lib’s SAR(acceleration, maximum): the starting factor and the step are the same number.
Verified by reading the plotted values off the chart against TA-Lib 0.8.1 on SPY daily, 250 bars (2025-08-25 to 2026-08-21): agreement to 1.1e-13, no long/short disagreements, and the SAR never sits inside a bar’s range.
Not verified on-chart: seeding is checked only in the Python model this script follows line for line. With more history loaded than the test window, the first nine bars differ from TA-Lib because the two start on different bars; they agree from there.
MIT license.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.