TrendPine Script v6

ta.supertrend()Supertrend

The Supertrend indicator is a trend-following overlay that uses ATR to calculate its values.

Syntax

Syntax
ta.supertrend(factor, atrPeriod) → [series float, series float]

Arguments

ParameterTypeDescription
factorsimple int/floatATR multiplier.
atrPeriodsimple intATR period.

Returns

Tuple of two series: supertrend line and direction (-1 for uptrend, 1 for downtrend).

Code Examples

Pine Script v6 Example
//@version=6
indicator("ta.supertrend")
[supertrend, direction] = ta.supertrend(3, 10)
plot(direction < 0 ? supertrend : na, "Up direction", color = color.green, style=plot.style_linebr)
plot(direction > 0 ? supertrend : na, "Down direction", color = color.red, style=plot.style_linebr)

Trading Applications

Identify clear trend direction with visual overlay

Use as a dynamic trailing stop

Generate buy/sell signals on direction changes

Combine with volume for breakout confirmation

Related Functions

Frequently Asked Questions

ta.supertrend() returns the Supertrend line and a direction value. The line is typically derived from median price and ATR bands; direction flips when price breaks the band, signaling a potential trend change.

In the documented Pine behavior for this tuple, direction -1 corresponds to uptrend state and 1 to downtrend state (as used in the example with green/red segments). Always verify on your chart against the plotted segments.

Factor and ATR period depend on volatility and timeframe. Shorter ATR periods react faster; larger multipliers widen bands and reduce whipsaws. Backtest and forward-test on your symbols.

Generate ta.supertrend() Code with AI

Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.supertrend() and other built-in functions instantly.