The Supertrend strategy is a trend-following approach built on the Supertrend indicator, which uses Average True Range (ATR) to place a volatility-adjusted trailing line above or below price. Traders watch the line flip from one side of price to the other as a signal that the prevailing direction may have changed. This page explains how the logic works, how traders typically interpret it, and the common pitfalls; it is educational and software-focused, makes no profit or win-rate claims, and nothing here is predictive — trading involves the risk of loss.
Supertrend draws a single line that follows price at a distance set by recent volatility. It starts from a midpoint (the average of the candle's high and low, often called hl2) and offsets it by a multiplier times the ATR over a chosen lookback. This produces two raw bands — an upper band above price and a lower band below it — but only one is shown at a time. When the close is above the active line, Supertrend sits below price and is read as an uptrend; when the close drops below the active line, the indicator flips to sit above price and is read as a downtrend. The line is "sticky": in an uptrend the lower band only ratchets upward (it never loosens), and in a downtrend the upper band only ratchets downward, so the line trails price like a volatility-aware stop. A signal occurs on the flip — the bar where direction changes from down to up (a potential long context) or up to down (a potential short or exit context). Because ATR widens in volatile conditions and narrows in calm ones, the line automatically gives price more room when ranges expand and tightens when they contract. The two inputs that shape everything are the ATR length (how many bars of volatility are averaged) and the multiplier (how far the line sits from price); larger values produce a slower, smoother line with fewer flips, while smaller values react faster but flip more often. To move from this idea to something you can trust, ForexCodes' Strategy Validator converts the logic into validated Pine Script v6 and checks it for look-ahead bias, repainting, and intent mismatches — try it free.
//@version=6
// Supertrend Trend-Following — educational example, not financial advice.
// Illustrative only: past performance does not indicate future results.
strategy("Supertrend Trend-Following (Educational)", overlay=true,
default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// --- Inputs ---
atrLength = input.int(10, "ATR Length", minval=1)
multiplier = input.float(3.0, "ATR Multiplier", minval=0.1, step=0.1)
tradeDir = input.string("Both", "Trade Direction",
options=["Long Only", "Short Only", "Both"])
// --- Supertrend (built-in; uses current and past data only, no look-ahead) ---
[supertrend, direction] = ta.supertrend(multiplier, atrLength)
// direction: -1 = uptrend (line below price), +1 = downtrend (line above price)
// Flip detection. On a live chart the current bar's direction can still change
// until the bar closes, so signals are evaluated on confirmed (closed) bars.
flipUp = direction < 0 and direction[1] > 0 // down -> up
flipDown = direction > 0 and direction[1] < 0 // up -> down
allowLong = tradeDir == "Long Only" or tradeDir == "Both"
allowShort = tradeDir == "Short Only" or tradeDir == "Both"
// --- Entries / exits (trend flip is the exit) ---
if allowLong and flipUp
strategy.entry("Long", strategy.long)
if allowShort and flipDown
strategy.entry("Short", strategy.short)
// Single-direction modes close opposite exposure on a flip
if not allowShort and flipDown
strategy.close("Long")
if not allowLong and flipUp
strategy.close("Short")
// --- Plot the trailing line for context ---
plot(supertrend, "Supertrend", color = direction < 0 ? color.teal : color.red,
linewidth = 2)There is no universally correct setting. A common starting reference is an ATR length around 10 with a multiplier around 3, but larger values give a slower, smoother line with fewer flips while smaller values react faster and flip more often. The right choice depends on your market, timeframe, and how much room you want the line to give price. Test changes carefully and remember that settings which fit past data well can still behave differently in live conditions — past results do not indicate future results.
The completed Supertrend line on closed bars does not change retroactively, but the value on the current, still-forming bar can move until that bar closes — which can look like repainting if you act intrabar. The safe practice is to evaluate flips on the bar close. If you pull Supertrend from a higher timeframe, use request.security() with look-ahead disabled (barmerge.lookahead_off) and read confirmed values so you are not borrowing future information. ForexCodes' Strategy Validator is built to flag exactly these look-ahead and repainting issues before you trust a backtest.
Yes — many traders use the line itself as a trailing reference because it ratchets in the trend's direction and never loosens until a flip. You can exit on the formal flip or treat the current line level as a stop. Either way, pair it with a hard protective stop, since a trend-following exit alone does not cap losses on a fast adverse move with gaps or slippage. None of this is predictive, and trading carries the risk of loss.
Educational & software only — not financial advice, not a recommendation to trade. Backtests are illustrative; past performance does not predict future results. Trading involves substantial risk of loss.