//@version=6
// Supertrend Trend Following — github.com/trugurpala/pinescriptv6
// Author: Ugur Pala · mail@ugurpala.com
strategy("Supertrend Strategy [trugurpala]",
overlay=true, initial_capital=10000,
default_qty_type=strategy.percent_of_equity, default_qty_value=10,
commission_type=strategy.commission.percent, commission_value=0.1)
// ── Inputs ───────────────────────────────────────────────────────────────────
int atrLen = input.int(10, "ATR Length", minval=1)
float atrMult = input.float(3.0, "ATR Multiplier", step=0.1)
bool longOnly = input.bool(false, "Long Only")
// ── Supertrend ───────────────────────────────────────────────────────────────
float atr = ta.atr(atrLen)
float upperBand = hl2 + atrMult * atr
float lowerBand = hl2 - atrMult * atr
var float superTrend = na
var int direction = 1
float prevUpper = nz(upperBand[1], upperBand)
float prevLower = nz(lowerBand[1], lowerBand)
upperBand := upperBand < prevUpper or close[1] > prevUpper ? upperBand : prevUpper
lowerBand := lowerBand > prevLower or close[1] < prevLower ? lowerBand : prevLower
if close > nz(superTrend[1], 0)
superTrend := lowerBand
direction := 1
else
superTrend := upperBand
direction := -1
bool bullSwitch = direction == 1 and direction[1] == -1
bool bearSwitch = direction == -1 and direction[1] == 1
// ── Entries ──────────────────────────────────────────────────────────────────
if bullSwitch
strategy.close("Short")
strategy.entry("Long", strategy.long)
if bearSwitch and not longOnly
strategy.close("Long")
strategy.entry("Short", strategy.short)
// ── Visuals ──────────────────────────────────────────────────────────────────
plot(superTrend, "ST", direction == 1 ? color.green : color.red, linewidth=3)
plotshape(bullSwitch, "Bull", shape.triangleup, location.belowbar, color.green, size=size.normal)
plotshape(bearSwitch, "Bear", shape.triangledown, location.abovebar, color.red, size=size.normal)
Overview
Supertrend Strategy [trugurpala] plots a color-coded trend line directly on the price chart along with buy and sell shapes. The strategy enters a long position when the Supertrend flips from bearish to bullish, and flips to a short position or closes long when it turns bearish. Users can adjust the ATR length, ATR multiplier, or restrict trades to long-only. The strategy operates without strict stop-loss or take-profit orders, relying entirely on trend reversal signals for exits.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
ATR Length
int
10
atrLen
ATR Multiplier
float
3.0
atrMult
Long Only
bool
false
longOnly
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 plots VWMA-based Bollinger bands on the 1-minute ES futures price chart for volatility analysis and potential breakout identification. It calculates dynamic long and short stop loss and take profit levels using percentage inputs relative to entry
This strategy runs on the price chart and enters long when a fast simple moving average crosses above a slow one, and short on the opposite cross, while closing the other side. Entries also need ATR above a filter, a pullback check, a minimum candle-body chang
This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the
This trend-following strategy adapts classic Donchian breakout channels according to market volatility regimes. It calculates an ATR percentile rank across a rolling lookback period, shifting dynamically between tighter breakout channels with smaller stops dur
This strategy executes breakout trades using two Donchian Channels alongside an optional 200-period EMA trend filter. Entries trigger when the price sets a new highest high or lowest low over the primary Donchian Channel period. Exits are managed via a shorter
This strategy implements a channel breakout system directly on the main price chart. It calculates highest highs and lowest lows over configurable entry and exit periods using historical candles. A long entry triggers when the close breaks above the entry chan