Supertrend
Pine Script indicator by Chart GT · Published
ATR-based trend line that flips sides when price closes through it.
Tags: trend, atr, trailing-stop
Source code
//@version=6
// @name Supertrend
// @description ATR-based trend line that flips sides when price closes through it.
// @tags trend,atr,trailing-stop
indicator("Supertrend", overlay=true)
atrPeriod = input.int(10, "ATR length", minval=1)
factor = input.float(3.0, "Factor", minval=0.1, step=0.1)
[st, direction] = ta.supertrend(factor, atrPeriod)
plot(direction < 0 ? st : na, "Up trend", color=color.green, style=plot.style_linebr, linewidth=2)
plot(direction > 0 ? st : na, "Down trend", color=color.red, style=plot.style_linebr, linewidth=2)
alertcondition(ta.change(direction) < 0, "Supertrend turned up", "Supertrend flipped to an up trend")
alertcondition(ta.change(direction) > 0, "Supertrend turned down", "Supertrend flipped to a down trend")
License: MPL-2.0
Open the chart to add it, or browse more community scripts.