ta.supertrend
Trail a volatility based stop and read the trend direction from its side.
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.
| Name | Kind | Type | Unit | Default | Range | Description |
|---|---|---|---|---|---|---|
factor | Constant | number | - | 3 | 0.001 to 50 | Multiples of the average true range the bands sit from hl2. |
atrPeriod | Constant | number | - | 10 | 1 to 10000 | Window of the average true range the bands are built from. |
bars | Constant | bars | bars | na | - | Which bars to read: a declared series, or na for the chart's own. |
Outputs
| Name | Type | Unit |
|---|---|---|
value | number | - |
direction | number | - |
The outputs come back in this order: [value, direction] = ta.supertrend(…).
Warm-up and missing values
- Warm-up
atrPeriodbars. 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 whilebarshas no bar available.
Example
[trend, direction] = ta.supertrend(3, 10)[trend, direction] = ta.supertrend(3, 10)
plot(trend, "Supertrend")