Documentation/AlgoCode/Function reference
supertrend
Supertrend line (ATR stop that flips with price).
supertrend(atrLength, factor)
Argument order is ATR length then factor — supertrend(10, 3). That is the Dovee/chart convention, not Pine’s (factor, atrPeriod). Put ATR length and factor on input lines so they show as knobs. Color the line with mask (green while close is above, red while below) — do not paint the background. buy and sell already draw the arrow and fill price.
Parameters
| Name | Type | Description |
|---|---|---|
atrLengthoptional | int default 10 | ATR period. |
factoroptional | float default 3 | ATR multiple. |
Return value
series
Note
- Defaults are length 10 and factor 3 if you write supertrend().
- buy / sell already mark the bar — skip arrow, label, and paint.
- To skip the flip bar and fill on a later high/low break, use valuewhen(flipUp, high) with barssince(flipUp) > 0. See the language tour.
Example
atrLen = input 10 as "ATR Length" factor = input 3 as "Factor" st = supertrend(atrLen, factor) stUp = mask(st, close is above st) stDown = mask(st, close is below st) plot stUp as "Supertrend Up" green plot stDown as "Supertrend Down" red when close crosses above st buy when close crosses below st sell