ta.supertrend()
Supertrend
The Supertrend indicator is a trend-following overlay that uses ATR to calculate its values.
Syntax
ta.supertrend(factor, atrPeriod) → [series float, series float]Arguments
| Parameter | Type | Description |
|---|---|---|
| factor | simple int/float | ATR multiplier. |
| atrPeriod | simple int | ATR period. |
Returns
Tuple of two series: supertrend line and direction (-1 for uptrend, 1 for downtrend).
Code Examples
//@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
Frequently Asked Questions
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.
Related Pine Script Functions
ta.atr() - Average True Range
Learn how to use ta.atr() in Pine Script. Syntax, parameters, code examples for the Average True Range volatility indicator.
ta.sar() - Parabolic SAR
Learn how to use ta.sar() in Pine Script. Syntax, parameters, code examples for the Parabolic Stop and Reverse indicator.
ta.macd() - MACD
Learn how to use ta.macd() in Pine Script. Syntax, parameters, code examples for MACD line, signal line, and histogram.
ta.dmi() - Directional Movement Index
Learn how to use ta.dmi() in Pine Script. Syntax, parameters, code examples for +DI, -DI, and ADX.
ta.ema() - Exponential Moving Average
Learn how to use ta.ema() in Pine Script. Syntax, parameters, code examples, and trading applications for the Exponential Moving Average function.