Indicator · Pine Script v6 · On the chart

Parabolic SAR

by everget

This indicator plots the Parabolic SAR on the price chart using TradingView's built-in SAR function.

View on GitHub

GitHub stars948on the repository
Pine versionv6current
Lines of code46
Settings7inputs
LicenceGPL-3.0
Last update10 days ago18 Oct 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

46 lines of Pine Script v6 from trailing_stops/parabolic_sar.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

parabolic_sar.pine
//@version=6
// Copyright (c) 2019-present, Alex Orekhov (everget)
// Parabolic SAR script may be freely distributed under the terms of the GPL-3.0 license.
indicator('Parabolic SAR', shorttitle = 'PSAR', overlay = true)

const string calcGroup = 'Calculation'
start = input.float(0.02, step = 0.001, title = 'Start', group = calcGroup)
increment = input.float(0.02, step = 0.001, title = 'Increment', group = calcGroup)
maximum = input.float(0.2, step = 0.01, title = 'Maximum', group = calcGroup)

const string visualGroup = 'Visuals'
width = input.int(2, minval = 1, title = 'Point Width', group = visualGroup)
showLabels = input.bool(true, title = 'Show Buy/Sell Labels', group = visualGroup)
highlightStartPoints = input.bool(true, title = 'Highlight Start Points', group = visualGroup)
highlightState = input.bool(true, title = 'Highlight State', group = visualGroup)

//---

psar = ta.sar(start, increment, maximum)
dir = psar < close ? 1 : -1

psarColor = dir == 1 ? #3388bb : #fdcc02
psarPlot = plot(psar, title = 'PSAR', style = plot.style_circles, linewidth = math.max(1, width), color = psarColor)

const color textColor = color.white
const color longColor = color.green
const color shortColor = color.red
const color longFillColor = color.new(color.green, 85)
const color shortFillColor = color.new(color.red, 85)

buySignal = dir == 1 and dir[1] == -1
plotshape(buySignal and highlightStartPoints ? psar : na, title = 'Long Start', location = location.absolute, style = shape.circle, size = size.tiny, color = longColor)
plotshape(buySignal and showLabels ? psar : na, title = 'Buy Label', text = 'Buy', location = location.absolute, style = shape.labelup, size = size.tiny, color = longColor, textcolor = textColor)

sellSignal = dir == -1 and dir[1] == 1
plotshape(sellSignal and highlightStartPoints ? psar : na, title = 'Short Start', location = location.absolute, style = shape.circle, size = size.tiny, color = shortColor)
plotshape(sellSignal and showLabels ? psar : na, title = 'Sell Label', text = 'Sell', location = location.absolute, style = shape.labeldown, size = size.tiny, color = shortColor, textcolor = textColor)

midPricePlot = plot(ohlc4, title = '', display = display.none, editable = false)

fillColor = highlightState ? (dir == 1 ? longFillColor : dir == -1 ? shortFillColor : na) : na
fill(midPricePlot, psarPlot, title = 'Trade State Filling', color = fillColor)

alertcondition(dir != dir[1], title = 'Direction Change', message = 'PSAR has changed direction, {{exchange}}:{{ticker}}')
alertcondition(buySignal, title = 'Long', message = 'PSAR Long, {{exchange}}:{{ticker}}')
alertcondition(sellSignal, title = 'Short', message = 'PSAR Sell, {{exchange}}:{{ticker}}')

Overview

Direction is long when the SAR sits below the close and short when it sits above. Circles mark the SAR and are colored by that direction. Optional buy and sell labels and start-point markers appear when the direction flips. A translucent fill between the mid price and the SAR shows the current state. Start, increment, and maximum set the acceleration factor; point width and highlight toggles change appearance. Alerts fire on direction changes and long or short flips. It does not place trades.

Details

Published by

everget on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

pinepinescripttechnical-indicatorsindicatorsoscillatorbandsaveragetradingviewindicatormoving-average

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Startfloat0.02start
Incrementfloat0.02increment
Maximumfloat0.2maximum
Point Widthint2width
Show Buy/Sell LabelsbooltrueshowLabels
Highlight Start PointsbooltruehighlightStartPoints
Highlight StatebooltruehighlightState
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

575 stars

This indicator detects equal highs and lows by comparing prices within user-defined left and right bars using a tolerance percentage. It plots horizontal lines on the price chart for equal highs in one color and lows in another. A screener allows input of mult

Indicator v5 Support & resistanceTrend
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows with Screener
330 stars

This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab

Indicator v4 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of 3 EMA/SMA + Cross [Alorse]
318 stars

This indicator calculates an ATR trailing stop line derived from the highest high minus an average true range multiple over a specified lookback period. It plots the trailing stop line directly on the price chart and colors price bars based on whether the clos

Indicator v5 TrendVolatility & bands
Updated 2 months ago · MIT GitHub repository of ATR Trailing Stoploss

All Candlestick Patterns

by shunjizhan
292 stars

All Candlestick Patterns detects and highlights a wide range of bullish, bearish, and neutral candlestick patterns directly on the price chart. It features optional trend filtering using either a 50-period simple moving average or a combination of 50-period an

Indicator v4 Candlestick patternsTrend
Updated 3 years ago · None stated GitHub repository of All Candlestick Patterns

NVDA Trend Ribbon

by longsurf-ai
277 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of NVDA Trend Ribbon

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers