Strategy · Pine Script v5 · On the chart

Parabolic SAR

by g-moe· code credited to goodgains

Parabolic SAR is a price-chart strategy that reads Commodity Channel Index and Parabolic SAR values from four user-selected timeframes.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code79
Settings12inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

79 lines of Pine Script v5 from Tradingview/parabolic-sar-v2.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

parabolic-sar-v2.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains



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

// @keywords: parabolic-sar, mtf-sar, cci-filter, strategy-entries, strategy-exits, multi-timeframe, sar-trailing, cci-threshold, long-short-signals, profit-target, sar-start-increment, four-timeframes, crossover-exits, mtf-cci, sar-dots, entry-conditions, exit-levels, overlay-strategy, sar-maximum, position-management

//INPUTS

//timeframes
tf1 = input.timeframe("1", title = 'Timeframe 1', group = 'Strategy Settings', inline = '1')
tf2 = input.timeframe("30", title = 'Timeframe 2', group = 'Strategy Settings', inline = '2')
tf3 = input.timeframe("60", title = 'Timeframe 3', group = 'Strategy Settings', inline = '3')
tf4 = input.timeframe("240", title = 'Timeframe 4', group = 'Strategy Settings', inline = '4')

//cci
cci_length = input.int(200, minval=1, title = 'CCI Length', group = 'Strategy Settings', inline = '5')
cci_src = input(hlc3, title="CCI Source", group = 'Strategy Settings', inline = '6')

cci_1 = request.security(syminfo.tickerid, tf1, ta.cci(cci_src, cci_length)[1], lookahead = barmerge.lookahead_on)
cci_2 = request.security(syminfo.tickerid, tf2, ta.cci(cci_src, cci_length)[1], lookahead = barmerge.lookahead_on)
cci_3 = request.security(syminfo.tickerid, tf3, ta.cci(cci_src, cci_length)[1], lookahead = barmerge.lookahead_on)
cci_4 = request.security(syminfo.tickerid, tf4, ta.cci(cci_src, cci_length)[1], lookahead = barmerge.lookahead_on)

// sar
sar_start = input(0.02, title = 'SAR Start', group = 'Strategy Settings', inline = '7')
sar_increment = input(0.02, title = 'SAR Increment', group = 'Strategy Settings', inline = '8')
sar_maximum = input(0.2, title = 'SAR Maximum', group = 'Strategy Settings', inline = '9')

sar_1 = request.security(syminfo.tickerid, tf1, ta.sar(sar_start, sar_increment, sar_maximum)[1], lookahead = barmerge.lookahead_on)
sar_2 = request.security(syminfo.tickerid, tf2, ta.sar(sar_start, sar_increment, sar_maximum)[1], lookahead = barmerge.lookahead_on)
sar_3 = request.security(syminfo.tickerid, tf3, ta.sar(sar_start, sar_increment, sar_maximum)[1], lookahead = barmerge.lookahead_on)
sar_4 = request.security(syminfo.tickerid, tf4, ta.sar(sar_start, sar_increment, sar_maximum)[1], lookahead = barmerge.lookahead_on)

//ORDERS
cci_entry_value = input.int(175,  title = 'CCI Entry Level', group = 'Strategy Settings', inline = '10')
cci_exit_value = input.int(-50, title = 'CCI Exit Level', group = 'Strategy Settings', inline = '11')

entry_price = strategy.position_avg_price
pt_amount = input.float(1.00, title = 'Profit Target', group = 'Strategy Settings', inline = '12')

//LONG
var long_cond = false
var long_entry = false
long_cond := (cci_1 > cci_entry_value) and (cci_2 > cci_entry_value) and (cci_3 > cci_entry_value) and (cci_4 > cci_entry_value) 
     and (close < sar_1) and (close < sar_2) and (close < sar_3) and (close < sar_4) ? true : false
long_entry := long_cond and not long_cond[1] ? true : false

var long_exit = false
long_exit := cci_1 < cci_exit_value and close < sar_1

long_profitTarget = (strategy.position_size > 0) ? entry_price + ((pt_amount/100) * entry_price) : 9999999
strategy.entry("LE", strategy.long,when = long_entry) 
// strategy.exit(id="LE", limit = long_profitTarget, comment = "Tgt")
strategy.close("LE",when = long_exit, comment = "LX")


//SHORT
// var short_cond = false
// var short_entry = false
// short_cond := (cci_1 > cci_entry_value) and (cci_2 > cci_entry_value) and (cci_3 > cci_entry_value) and (cci_4 > cci_entry_value) 
//      and (close < sar_1) and (close < sar_2) and (close < sar_3) and (close < sar_4) ? true : false
// short_entry := short_cond and not short_cond[1] ? true : false

// var short_exit = false
// short_exit := cci_1 < cci_exit_value and close < sar_1

// short_profitTarget = (strategy.position_size < 0) ? entry_price - ((pt_amount/100) * entry_price) : 0
// strategy.entry("SS_E", strategy.short, when = short_entry) 
// strategy.exit(id="SS_E", limit = short_profitTarget, comment = "Tgt")
// strategy.close("SS_E",when = short_exit, comment = "SS_X")


// plot(entry_price, color = color.white)
// plot(long_profitTarget)
// plot(short_profitTarget)

Overview

Parabolic SAR opens a long when every timeframe’s CCI is above the entry level and price is below every SAR, and it closes that long when the first timeframe’s CCI falls below the exit level while price is under that SAR. Settings change the four timeframes, CCI length and source, SAR start, increment and maximum, and the two CCI levels. A profit-target value is calculated, but the related exit is commented out, so there is no stop loss and no active short logic.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Settings

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

SettingTypeDefaultVariable
Timeframe 1timeframe1tf1
Timeframe 2timeframe30tf2
Timeframe 3timeframe60tf3
Timeframe 4timeframe240tf4
CCI Lengthint200cci_length
CCI Sourcesourcehlc3cci_src
SAR Startfloat0.02sar_start
SAR Incrementfloat0.02sar_increment
SAR Maximumfloat0.2sar_maximum
CCI Entry Levelint175cci_entry_value
CCI Exit Levelint-50cci_exit_value
Profit Targetfloat1.00pt_amount
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

330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy
285 stars

Mean Reversion Strategy is an overlay strategy that identifies pullbacks using a long-term EMA, RSI, and candlestick patterns. It generates long signals when a bullish engulfing candle forms below the EMA while RSI is oversold, and short signals when a bearish

Strategy v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Strategy
228 stars

This strategy generates trading signals based on a selectable momentum engine, supporting MACD, RSI, Stochastic, or Rate of Change. Entries trigger on signal crosses, zero-line crosses, or threshold crosses, with an optional moving average trend filter. Risk m

Strategy v6 Oscillators & momentumTrend
Updated 3 months ago · None stated GitHub repository of Momentum Strategy Template

255 EMA Strategy

by hasnocool
106 stars

255 EMA Strategy combines an exponential moving average with Average True Range bands and standard MACD crossovers to generate entry signals. Drawn directly on the price chart, it plots the central 255 EMA along with upper and lower volatility envelopes. Trade

Strategy v4 Moving averagesOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 255 EMA Strategy

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers