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.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.