Docs

ta.supertrend

Trail a volatility based stop and read the trend direction from its side.

itm
ta.supertrend(factor, atrPeriod, bars)

Supertrend: [trailing band, direction]. Bands are hl2 +/- factor*ta.atr(atrPeriod), each ratcheted so it only moves toward price until the previous close breaks it. The band in force flips when the close crosses it. Direction is -1 while the trend is up (the value is the lower band) and +1 while it is down. The first warmed bar seeds direction +1 with unratcheted bands.

Parameters

A series parameter takes a value on every bar. A constant parameter must be known before the first bar, such as a number or an input.

NameKindTypeUnitDefaultRangeDescription
factorConstantnumber-30.001 to 50Multiples of the average true range the bands sit from hl2.
atrPeriodConstantnumber-101 to 10000Window of the average true range the bands are built from.
barsConstantbarsbarsna-Which bars to read: a declared series, or na for the chart's own.

Outputs

NameTypeUnit
valuenumber-
directionnumber-

The outputs come back in this order: [value, direction] = ta.supertrend(…).

Warm-up and missing values

Warm-up
atrPeriod bars. Names in the warm-up are this operator’s parameters.
Missing values
Both outputs are na until the average true range has warmed up over atrPeriod, and na while bars has no bar available.

Example

itm
[trend, direction] = ta.supertrend(3, 10)
itm
[trend, direction] = ta.supertrend(3, 10)
plot(trend, "Supertrend")