A dynamic stop-loss that moves with price in the direction of the trade, locking in profits as the trend continues.
A trailing stop moves in the direction of a profitable trade but never reverses against you. If you are long and price rises, the stop rises with it. If price then drops back, the stop holds where it is and eventually gets hit. The stop only ever moves in the direction that locks in more profit — it never gives ground back.
This is different from a fixed stop-loss, which stays at the level you set it when you entered. A trailing stop dynamically adjusts as the trade moves in your favour, so you are continuously protecting gains that didn't exist when you opened the position.
Fixed take-profits cap your upside. If you set a target 20 points above entry and the market runs 100 points, you collected 20 of them. A trailing stop lets a winning trade run as far as it is willing to go while protecting the gains accumulated so far.
The tradeoff is that you will always give back some profit when price reverses to trigger the stop. The question is how tight to set the trail — too tight and you get stopped out during normal pullbacks; too loose and you give back too much. ATR is the natural answer: it measures how much the instrument actually moves, so a multiple of ATR gives you a trail that breathes with the market's own volatility.
The Supertrend indicator is essentially an ATR-based trailing stop with a built-in flip mechanism for direction — it is the same concept made visual.
//@version=6
strategy("Trailing Stop Demo", overlay=true)
atrValue = ta.atr(14)
atrMultiple = input.float(2.0, "ATR Multiple", minval=0.5, step=0.5)
longCondition = ta.crossover(ta.ema(close, 9), ta.ema(close, 21))
// Method 1: Pine Script built-in trailing stop via strategy.exit
if longCondition
strategy.entry("Long", strategy.long)
strategy.exit("Trail Exit", "Long",
trail_points = atrValue * atrMultiple / syminfo.mintick,
trail_offset = atrValue * atrMultiple / syminfo.mintick)
// Method 2: Manual ATR trail for visualisation
// var makes the variable persist across bars; math.max ratchets it upward only
var float trailStop = na
if strategy.position_size > 0
trailStop := math.max(nz(trailStop, low), close - atrValue * atrMultiple)
else
trailStop := na
plot(trailStop, "ATR Trailing Stop", color=color.orange, linewidth=2, style=plot.style_linebr)
Key takeaway: Trailing stops work best in trending markets. In choppy, range-bound conditions they get hit repeatedly before a trend develops, resulting in a string of small losses. Pair them with a trend filter or an ADX threshold — activate the trailing exit only on trades that are already showing directional momentum.