Pine Script Parabolic SAR (Stop and Reverse)

Master this powerful trend-following indicator in TradingView's Pine Script for dynamic stop-loss placement and trend reversal identification.

Subscribe now @ $99/month

What is Parabolic SAR?

The Parabolic Stop and Reverse (SAR) indicator, developed by J. Welles Wilder Jr., is a time and price based trading tool used to determine the direction of an asset's momentum and the point at which to place a stop-loss or take profit. It's often visualized as a series of dots, either above or below the price bars, indicating the current trend direction.

A primary strength of the Parabolic SAR is its ability to adapt to accelerating trends. As a trend develops, the SAR dots accelerate towards the price, tightening the stop-loss level and locking in more profits. When the trend reverses, the dots "stop and reverse" to the other side of the price, signaling a potential new trend.

Components and Calculation

The Parabolic SAR calculation involves several key elements:

The SAR calculation is complex and recursive, but essentially, it determines the SAR value for the current bar based on the previous SAR value, the Extreme Point of the current trend, and the Acceleration Factor. The AF increases as the trend progresses, making the SAR line accelerate towards the price.

Basic Parabolic SAR Implementation in Pine Script

Pine Script v5 makes implementing Parabolic SAR very straightforward with the built-in `ta.sar()` function.

//@version=5
indicator("My Parabolic SAR Indicator", overlay=true)

// Inputs for Parabolic SAR parameters
start = input.float(0.02, title="Start AF")
increment = input.float(0.02, title="Increment")
maximum = input.float(0.20, title="Maximum AF")

// Calculate Parabolic SAR using the built-in function
sarValue = ta.sar(start, increment, maximum)

// Plot the Parabolic SAR dots
// Color dots based on whether SAR is below (uptrend) or above (downtrend) the price
plot(sarValue, "SAR", style=plot.style_circles, linewidth=2, color=sarValue < close ? color.green : color.red)
Key Interpretation: When the dots are below the price bars, it signals an uptrend. When the dots are above the price bars, it signals a downtrend. A dot switching sides indicates a trend reversal.

Practical Parabolic SAR Strategies

1. Trend Following and Reversal Signals

The most direct application of Parabolic SAR is for trend identification and reversal signals. It's a stop-and-reverse system by design:

//@version=5
strategy("Parabolic SAR Trend Strategy", overlay=true)

start = input.float(0.02, title="Start AF")
increment = input.float(0.02, title="Increment")
maximum = input.float(0.20, title="Maximum AF")

// Calculate Parabolic SAR
sarValue = ta.sar(start, increment, maximum)

// Determine if SAR has flipped (trend reversal)
longCondition = ta.crossover(close, sarValue)
shortCondition = ta.crossunder(close, sarValue)

// Strategy entries/exits
if (longCondition)
    strategy.entry("Long", strategy.long)
    
if (shortCondition)
    strategy.entry("Short", strategy.short)

// Plot SAR
plot(sarValue, "SAR", style=plot.style_circles, linewidth=2, color=sarValue < close ? color.green : color.red)

2. Parabolic SAR as a Dynamic Stop-Loss / Trailing Stop

Parabolic SAR is an excellent tool for placing dynamic stop-loss orders. As the trend progresses, the SAR dots move closer to the price, effectively trailing the market. This helps protect profits while still allowing the trade to run.

//@version=5
strategy("Parabolic SAR Dynamic Stop-Loss", overlay=true)

// Inputs for Parabolic SAR
start = input.float(0.02, title="Start AF")
increment = input.float(0.02, title="Increment")
maximum = input.float(0.20, title="Maximum AF")

// Calculate Parabolic SAR
sarValue = ta.sar(start, increment, maximum)

// Example entry logic (e.g., simple moving average crossover)
fastMA = ta.ema(close, 20)
slowMA = ta.ema(close, 50)
longEntry = ta.crossover(fastMA, slowMA)
shortEntry = ta.crossunder(fastMA, slowMA)

// Long strategy with SAR as stop-loss
if (longEntry)
    strategy.entry("Buy", strategy.long)
    strategy.exit("Long Exit", from_entry="Buy", stop=sarValue) // SAR as trailing stop

// Short strategy with SAR as stop-loss
if (shortEntry)
    strategy.entry("Sell", strategy.short)
    strategy.exit("Short Exit", from_entry="Sell", stop=sarValue) // SAR as trailing stop

// Plot SAR
plot(sarValue, "SAR", style=plot.style_circles, linewidth=2, color=sarValue < close ? color.green : color.red)

Optimizing Parabolic SAR Performance

To get the most out of Parabolic SAR in Pine Script:

Caution: Parabolic SAR is a trend-following indicator. It performs poorly in sideways or range-bound markets, where it can generate frequent false signals. Always use it with a trend filter.

Common Parabolic SAR Pitfalls

Conclusion

The Parabolic SAR is a unique and effective indicator in Pine Script for identifying trends and managing trades with dynamic stop-loss levels. Its ability to accelerate towards price makes it excellent for capturing profits in strong trends. By understanding its calculation and combining it judiciously with other indicators and market analysis, you can leverage Parabolic SAR to enhance your TradingView strategies and improve your trade management.

Enhance Your Trading

Get a high-performance Pine Script analysis tool for actionable market insights, designed for traders on the move.

This strategy runs in live mode on TradingView, helping you identify potential opportunities.

Subscribe now @ $99/month