← Back to Library
Trend

Supertrend

Supertrend is a trend-following indicator plotted on price charts. It changes color based on trend direction and is excellent for trailing stop-losses. This V6 code allows customization of the ATR factor.

Pine Script V6
//@version=6
indicator('Supertrend', overlay=true)
factor = input.float(3.0, 'Factor')
atrPeriod = input.int(10, 'ATR Period')
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
plot(direction < 0 ? supertrend : na, 'Up Trend', color=color.green, style=plot.style_linebr)
plot(direction > 0 ? supertrend : na, 'Down Trend', color=color.red, style=plot.style_linebr)