//@version=4
strategy(title="ATR Parabolic SAR Strategy [QuantNomad]", shorttitle="ATR PSAR Strategy [QN]", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)
atr_length = input(14)
start = input(0.02)
increment = input(0.02)
maximum = input(0.2)
entry_bars = input(1, title = "Entry on Nth trend bar")
atr = atr(atr_length)
atr := na(atr) ? tr : atr
psar = 0.0 // PSAR
af = 0.0 // Acceleration Factor
trend_dir = 0 // Current direction of PSAR
ep = 0.0 // Extreme point
trend_bars = 0
sar_long_to_short = trend_dir[1] == 1 and close <= psar[1] // PSAR switches from long to short
sar_short_to_long = trend_dir[1] == -1 and close >= psar[1] // PSAR switches from short to long
trend_change = barstate.isfirst[1] or sar_long_to_short or sar_short_to_long
// Calculate trend direction
trend_dir := barstate.isfirst[1] and close[1] > open[1] ? 1 :
barstate.isfirst[1] and close[1] <= open[1] ? -1 :
sar_long_to_short ? -1 :
sar_short_to_long ? 1 : nz(trend_dir[1])
trend_bars := sar_long_to_short ? -1 :
sar_short_to_long ? 1 :
trend_dir == 1 ? nz(trend_bars[1]) + 1 :
trend_dir == -1 ? nz(trend_bars[1]) - 1 :
nz(trend_bars[1])
// Calculate Acceleration Factor
af := trend_change ? start :
(trend_dir == 1 and high > ep[1]) or
(trend_dir == -1 and low < ep[1]) ?
min(maximum, af[1] + increment) :
af[1]
// Calculate extreme point
ep := trend_change and trend_dir == 1 ? high :
trend_change and trend_dir == -1 ? low :
trend_dir == 1 ? max(ep[1], high) :
min(ep[1], low)
// Calculate PSAR
psar := barstate.isfirst[1] and close[1] > open[1] ? low[1] :
barstate.isfirst[1] and close[1] <= open[1] ? high[1] :
trend_change ? ep[1] :
trend_dir == 1 ? psar[1] + af * atr :
psar[1] - af * atr
plot(psar, style=plot.style_cross, color=trend_dir == 1 ? color.green : color.red, linewidth = 2)
// Strategy
strategy.entry("Long", true, when = trend_bars == entry_bars)
strategy.entry("Short", false, when = trend_bars == -entry_bars)
Expand (62 lines)
Overview
ATR Parabolic SAR Strategy [QuantNomad] calculates the SAR line, acceleration factors, and extreme points directly on the price chart. When a trend reversal occurs and persists for a user-defined number of bars, the strategy executes long or short position entries. The main inputs allow customization of the ATR length, acceleration factor parameters (start, increment, maximum), and entry bar threshold. It plots color-coded PSAR crosses directly on price candles and relies on trend reversals to exit without dedicated stop-loss orders.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
atr_length
int
14
atr_length
start
float
0.02
start
increment
float
0.02
increment
maximum
float
0.2
maximum
Entry on Nth trend bar
int
1
entry_bars
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.
This strategy calculates Bollinger Bands and Aroon oscillator values to identify mean-reversion opportunities. It enters a long position using full equity when the closing price crosses below the lower Bollinger Band while Aroon Up remains above a user-specifi
This overlay strategy targets one-minute ES futures and plots volume-weighted moving-average bands from the open, scaled by a standard-deviation multiple, plus a slower band from ten-minute opens. A higher-timeframe exponential moving average can filter trades
STRG-BBForce is a Bollinger Bands trend-following strategy. It calculates standard Bollinger Bands and tracks directional alignment across the upper, lower, and basis lines. When all three lines slope upward, it opens a long position and closes short positions
This strategy uses multiple VWAP anchors and a custom Lull indicator to generate buy and sell signals on the Nasdaq price chart. It plots the VWAP trend line and three VWAP anchors with customizable colors and mitigation methods. The Lull indicator produces si
This strategy implements a single-layer perceptron machine learning model built from scratch to generate trading signals directly on the price chart. It calculates predictions based on sample size, threshold settings, and optional volatility or volume filters.
This strategy generates buy and sell signals based on Bollinger Band crossovers combined with a simple moving average trend filter. It enters a long position when price crosses above the lower band while trading above the SMA filter line, and enters a short po