Concept 38 / 52·Trend·Trailing trend lines
‹ Overbought & OversoldPivot Points ›

Parabolic SAR in Pine Script

PSAR · SAR · stop and reverse · parabolic stop and reverse

A trailing stop drawn as dots that accelerate towards price as a trend ages, flipping to the other side of the bar when price touches them, so the position is always long or short.

Reads best on: Trending instruments on 1 hour to daily charts: commodities, currency trends, crypto and momentum stocks. In ranges and on very low timeframes the flips come every few bars.
On this page: the Pine v6 script, checked, drawn on real NVDA bars. Backtest it free, costs charged, every trade on the chart.
Backtest results: Parabolic SAR strategy: SPY, QQQ and more since 2016, costs charged, every trade listed.
01

Definition

Parabolic SAR (stop and reverse) is a trailing stop that follows price as a series of dots below an uptrend and above a downtrend. Each bar the dot moves towards price by a fraction of the distance to the extreme of the move, and that fraction grows every time the trend makes a new extreme, so the dots trace a parabola that closes in on price as the trend ages. When price crosses the dots the trend flips, the dots jump to the other side, and the acceleration restarts. It belongs to the trailing trend lines family.

The tool works because trends age. A move that keeps making new highs deserves a stop that tightens, and a move that stops making them deserves to be stopped out; the accelerating dots do both automatically. Early in a trend the dots sit far away and the trade has room; later they climb steeply and the exit comes on the first real pause. The design assumes the market is always trending one way or the other, which is why it reverses rather than exits, and why it suffers in ranges.

J. Welles Wilder published Parabolic SAR in 1978 with the settings that are still the default: an acceleration factor starting at 0.02, rising by 0.02 with each new extreme, and capped at 0.20. The library's implementation draws the dots green while price is above them and red while below, and marks Long on the confirmed bar price first closes above the dots and Short on the first close below, with an optional alert on each flip.

On the chart the dots start each trend far from price and curve towards it. In a strong trend the curve steepens as the acceleration factor grows and the dots can sit inside a normal pullback by the time the trend is a few weeks old, which produces the exit. In a range the dots flip every few bars, each flip placing the new dots at the previous extreme, so the tool whipsaws and each reversal loses. The dots never rise in a downtrend or fall in an uptrend.

02

Reading the chart

SAR is dots and a side, so reading it is about where the dots are in their curve and whether the market is trending enough for them to mean anything.

  1. Confirm the settings. A start of 0.02, an increment of 0.02 and a maximum of 0.20 are Wilder's defaults and the ones most charts show; anything else changes how fast the dots close in.
  2. Read the side. Dots below price mean the tool is long and the trend is up on this timeframe; dots above price mean short. There is no neutral state.
  3. Note the age of the curve. Dots far from price with a shallow curve mean a young trend with room; dots climbing steeply into the candles mean an old trend near its stop.
  4. Judge each flip by the run before it. A flip after a long run of one colour is a trend ending; a flip within a few bars of the last one is range noise.
  5. Use the dot as the stop. The distance from the close to the current dot is the risk on the trade, and it shrinks every bar in a trend.
  6. Confirm the regime with ADX or a moving average slope. SAR is designed for trends, and its flips in a range are best ignored altogether.
03

The maths

Each bar the stop moves towards the extreme point of the trend by the acceleration factor, and the factor grows with each new extreme up to its cap.

SARt+1={EPtFlipt=1SARt+AFt (EPt−SARt)otherwise\mathrm{SAR}_{t+1} = \begin{cases} \mathrm{EP}_t & \mathrm{Flip}_t = 1 \\ \mathrm{SAR}_t + \mathrm{AF}_t \, (\mathrm{EP}_t - \mathrm{SAR}_t) & \text{otherwise} \end{cases}
AFt={AF0Flipt=1min⁡(AFt−1+step, AFmax⁡)EPt≠EPt−1AFt−1otherwise\mathrm{AF}_t = \begin{cases} \mathrm{AF}_0 & \mathrm{Flip}_t = 1 \\ \min(\mathrm{AF}_{t-1} + \mathrm{step},\, \mathrm{AF}_{\max}) & \mathrm{EP}_t \ne \mathrm{EP}_{t-1} \\ \mathrm{AF}_{t-1} & \text{otherwise} \end{cases}
Flipt={1Dirt=up∧Lt≤SARt1Dirt=down∧Ht≥SARt0otherwise\mathrm{Flip}_t = \begin{cases} 1 & \mathrm{Dir}_t = \text{up} \land L_t \le \mathrm{SAR}_t \\ 1 & \mathrm{Dir}_t = \text{down} \land H_t \ge \mathrm{SAR}_t \\ 0 & \text{otherwise} \end{cases}
SARt\mathrm{SAR}_tthe stop and reverse value drawn on bar t
EPt\mathrm{EP}_tthe extreme point of the current trend: the highest high in an uptrend, the lowest low in a downtrend
AFt\mathrm{AF}_tthe acceleration factor on bar t
step\mathrm{step}the increment added to AF on each new extreme, 0.02 by default
AFmax\mathrm{AF}_{max}the cap on the acceleration factor, 0.20 by default
AF0\mathrm{AF}_0the start value of the acceleration factor on the bar of a flip, 0.02 by default
Ht,LtH_t, L_tthe high and low of bar t
Dirt\mathrm{Dir}_tthe direction of the trend in force on bar t, up or down
Flipt\mathrm{Flip}_t1 on the bar where price touches the stop and the trend reverses, else 0

The start value and the increment are separate inputs: the start sets the factor on the bar after a flip, and the increment is what each new extreme adds; both are 0.02 by default.

Wilder's rule keeps the stop outside the previous 2 bars' range, so in an uptrend the SAR can never be above the low of the current or the prior bar.

On the first bar after a flip the SAR is placed at the extreme point of the old trend, which is why the new dots start far from price.

The library's script flips on the close crossing the dots on a confirmed bar; the platform's built-in calculation flips when the high or low touches them, so the mark and the dot colour change on the same bar in almost every case.

04

Inputs that matter

InputTypicalWhat changing it does
Start0.02A higher start puts the dots on a steeper path from the first bar after a flip, which tightens the early stop and raises the number of reversals.
Increment (step)0.02A larger step makes the dots close in faster with each new extreme, so trends end sooner; a smaller step gives the trend more room and exits later.
Maximum0.20The cap limits how steep the curve can get in a long trend; lowering it keeps a mature trend alive through deeper pullbacks.
05

In practice

  • As a trailing stop: the rule holds a trend trade with the stop at the current dot and lets the acceleration decide the exit. This is the tool's original purpose and its best use.
  • As a trend state: dots below price permit longs and dots above price permit shorts, which gives a simple side for other entry tools to obey.
  • As a reversal trigger in trending markets: the library's script marks Long and Short on the flips; a filter keeps them only when a regime filter such as ADX above 25 says the market is trending.
  • As an exit for another entry: the rule enters on a breakout or a pullback and exits on the SAR flip, which removes the decision of when a trend is over.
  • As a time-based tightening: because the dots accelerate with age rather than volatility, the tool exits a stalled trend that a volatility stop would sit through.
  • As a flip alert: the indicator's alerts fire once per confirmed flip, so a watchlist of charts can report its changes of side without anyone watching the dots.
06

Where it goes wrong

  • Trading SAR flips in a range. The dots reverse every few bars and each reversal loses; use a trend filter and ignore the flips when it says the market is flat.
  • Confusing the dots with support and resistance. They are a stop level that moves every bar by formula, not a place other traders have orders.
  • Raising the step to catch turns faster. A step of 0.05 exits most trends on their first pause; if you want faster exits, use the default and a lower timeframe.
  • Entering on a flip far from the new dot. The first bars after a flip carry the widest stop; size for that distance or wait for the dots to close in.
07

Compared with

SuperTrend. SuperTrend trails at a fixed multiple of ATR and only tightens when price makes progress, so it sits through long pauses. SAR tightens with time regardless of volatility, which exits stalled trends sooner and whipsaws more in ranges.

Chandelier Exit. The Chandelier Exit trails a multiple of ATR below the highest high and never accelerates; its distance depends on volatility, not on the trend's age. SAR's distance shrinks by formula every bar, so the two behave differently in a slow, steady trend.

Trailing Stop. A generic trailing stop follows price at a fixed distance in percent or ATR. SAR is a trailing stop whose distance is a parabola in time, and it reverses the position instead of just closing it.

Moving Average. A moving average can be crossed many times without a regime change and moves both ways. SAR only moves in the trend's favour and always flips on a cross, so it gives a two-state reading where the average gives a level.

08

Build it in Quant

Type one of these in the Quant desk, or click it. A request that fits a checked template is assembled on the spot without a credit; anything beyond the blanks goes to the copilot, which edits on top of the checked script.

Open Parabolic SAR on the workbench chart
Drawn on real data; then audit, backtest and refine in conversation.
Open in Quant →
09

Questions

  • What do the Parabolic SAR settings mean?

    Three numbers control the curve. The start is the acceleration factor on the first bar after a flip, 0.02 by default. The increment is added to the factor each time the trend makes a new extreme, also 0.02. The maximum caps the factor at 0.20. Together they set how quickly the dots close in on price.

  • Why does Parabolic SAR whipsaw so much?

    Because it assumes the market is always trending and reverses on every touch. In a range price returns to the middle every few bars, the dots flip, the new dots start at the last extreme, and price returns to touch them again. Wilder designed it for trends and expected a filter to keep it out of ranges.

  • Is SAR better as an entry or an exit?

    As an exit. The accelerating stop is a good way to let a trend run and leave when it stalls, which is what stop and reverse means. As an entry it is late and it fires in ranges. Most traders enter with another tool and use the SAR dot as the trailing stop, ignoring the flips in the other direction.

  • Does Parabolic SAR repaint?

    No. Each dot is computed from closed bars and the previous dot, and the library's script marks a flip only on a confirmed bar. The dot for the current bar is known at its open, which is one of the tool's strengths: the stop for the coming bar is fixed before it starts.

  • Can I change the settings for a faster or slower SAR?

    Yes. A start and step of 0.01 with a maximum of 0.10 gives a slow SAR that survives deeper pullbacks and suits daily charts of trending stocks. 0.03 or 0.04 with a maximum of 0.3 gives a fast SAR for intraday momentum that exits on the first pause. Test on the instrument, because the right speed depends on how it trends.

  • How do I combine SAR with ADX?

    ADX serves as the permission and SAR as the trigger and stop. A SAR flip counts only when ADX is above 25, which says the market is trending enough for the dots to mean something, and the flips below it are ignored. Wilder published both tools together for exactly this pairing.