What it does
Parabolic SAR Trend plots J. Welles Wilder's Parabolic Stop and Reverse as a trail of dots. The dots sit below price in an uptrend and above it in a downtrend, and each time price closes on the other side of them, the trend flips.
This version colors the dots by trend, marks every flip on a closed bar, and adds an optional EMA trend filter. With the filter on, flips that agree with the EMA trend get a full Bull or Bear label. Flips against it are shown as small grey triangles, so you can still see them without confusing them with trend-aligned signals.
How it works
The SAR uses TradingView's built-in ta.sar with the standard rules:
- In an uptrend, next SAR = current SAR + AF × (extreme point − current SAR), where the extreme point is the highest high of the trend. In a downtrend, the lowest low is used.
- The acceleration factor (AF) starts at the Start value, rises by the Increment every time a new extreme is made, and is capped at the Maximum.
- When price crosses the SAR, the trend reverses, the SAR resets to the prior extreme point and AF resets to the Start value.
The script treats the trend as bullish when the close is above the SAR and bearish when it is below. A flip is a change of that state, checked only on confirmed bars.
Trend filter: a bullish flip counts as with-trend when the close is above the EMA, and a bearish flip when the close is below it. All other flips are counter-trend. Alerts are split into with-trend and counter-trend versions.
How to use it
- Use the dots as a trailing reference. In an uptrend, the dots rise faster as the trend extends, which tightens a stop-loss placed near them.
- With-trend flips after a pullback are the signals most traders focus on. Grey flips often mark the end of a pullback rather than a new trend.
- Parabolic SAR is always in the market, long or short, so it needs a filter in sideways conditions. The EMA filter is one option; pairing it with support and resistance is another.
- The default 0.02 / 0.02 / 0.2 settings are a common starting point on H1–D1. Lower values make the dots slower and the flips less frequent.
Settings
| Input | Default | What it changes |
|---|---|---|
| Start (acceleration) | 0.02 | Initial speed of the dots after a flip. |
| Increment | 0.02 | How quickly the dots accelerate as the trend extends. |
| Maximum | 0.2 | Fastest possible speed. Higher = tighter trailing. |
| Grey out counter-trend flips | On | Applies the EMA filter. |
| Trend EMA length | 200 | Speed of the trend filter. |
| Show trend EMA | On | Draws the filter EMA on the chart. |
| Show flip labels | On | Labels and grey markers on flips. |
Limitations
- In ranges, Parabolic SAR flips back and forth, and each flip can be a loss if traded mechanically.
- The acceleration makes the dots close in on price in long trends, so a normal pullback can trigger a flip before the trend is really over.
- The EMA filter lags. Near trend changes it will grey out early valid flips and keep late ones.
- Flips are confirmed on bar close. In live trading a stop at the SAR level would be hit intrabar, and gaps can fill beyond it.
Pine Script source
In TradingView open Pine Editor, paste the code, click Save and then Add to chart.
FXP_ParabolicSarTrend.pine
57 lines
// © FXPIPS ONLINE — https://fxpips.online/tradingview-indicators/parabolic-sar-trend/
// License: MIT. Educational tool — not financial advice. Trading involves substantial risk.
//@version=6
// Parabolic SAR dots colored by trend, with flip signals confirmed on bar close and an optional
// EMA trend filter: flips against the EMA trend are drawn grey and do not trigger the main alerts.
indicator("FXP Parabolic SAR Trend", shorttitle = "FXP PSAR", overlay = true)
// ── Inputs ─────────────────────────────────────────────────────────────
grpS = "Parabolic SAR"
sarStart = input.float(0.02, "Start (acceleration)", minval = 0.001, step = 0.001, group = grpS)
sarInc = input.float(0.02, "Increment", minval = 0.001, step = 0.001, group = grpS)
sarMax = input.float(0.2, "Maximum", minval = 0.01, step = 0.01, group = grpS)
grpF = "Trend filter"
useFilter = input.bool(true, "Grey out counter-trend flips", group = grpF, tooltip = "A bullish flip below the EMA, or a bearish flip above it, is shown grey and excluded from the main alerts.")
emaLen = input.int(200, "Trend EMA length", minval = 2, group = grpF)
showEma = input.bool(true, "Show trend EMA", group = grpF)
grpV = "Display"
showSignals = input.bool(true, "Show flip labels", group = grpV)
colBull = input.color(#26a69a, "Bullish color", group = grpV)
colBear = input.color(#ef5350, "Bearish color", group = grpV)
colMuted = input.color(#9e9e9e, "Counter-trend color", group = grpV)
colEma = input.color(#ff9800, "EMA color", group = grpV)
// ── Calculation ────────────────────────────────────────────────────────
sar = ta.sar(sarStart, sarInc, sarMax)
trendMa = ta.ema(close, emaLen)
int dir = close > sar ? 1 : -1
prevDir = nz(dir[1], dir)
flipUp = dir == 1 and prevDir == -1 and barstate.isconfirmed
flipDown = dir == -1 and prevDir == 1 and barstate.isconfirmed
withTrendUp = not useFilter or close > trendMa
withTrendDown = not useFilter or close < trendMa
bullSignal = flipUp and withTrendUp
bearSignal = flipDown and withTrendDown
bullCounter = flipUp and not withTrendUp
bearCounter = flipDown and not withTrendDown
// ── Plots ──────────────────────────────────────────────────────────────
plot(sar, "Parabolic SAR", color = dir == 1 ? colBull : colBear, style = plot.style_circles, linewidth = 2)
plot(showEma ? trendMa : na, "Trend EMA", color = colEma, linewidth = 1)
plotshape(showSignals and bullSignal, "Bullish flip", style = shape.labelup, location = location.belowbar, color = colBull, text = "Bull", textcolor = color.white, size = size.small)
plotshape(showSignals and bearSignal, "Bearish flip", style = shape.labeldown, location = location.abovebar, color = colBear, text = "Bear", textcolor = color.white, size = size.small)
plotshape(showSignals and bullCounter, "Counter-trend bullish flip", style = shape.triangleup, location = location.belowbar, color = colMuted, size = size.tiny)
plotshape(showSignals and bearCounter, "Counter-trend bearish flip", style = shape.triangledown, location = location.abovebar, color = colMuted, size = size.tiny)
// ── Alerts ─────────────────────────────────────────────────────────────
alertcondition(bullSignal, "PSAR bullish flip (with trend)", "Parabolic SAR flipped bullish with the trend on {{ticker}} ({{interval}})")
alertcondition(bearSignal, "PSAR bearish flip (with trend)", "Parabolic SAR flipped bearish with the trend on {{ticker}} ({{interval}})")
alertcondition(bullCounter, "PSAR bullish flip (counter-trend)", "Parabolic SAR flipped bullish against the EMA trend on {{ticker}} ({{interval}})")
alertcondition(bearCounter, "PSAR bearish flip (counter-trend)", "Parabolic SAR flipped bearish against the EMA trend on {{ticker}} ({{interval}})")

