Supertrend

Calculates the Supertrend indicator.

Accepts the following parameters:

Parameter NameTypeDefault ValueNotes
periodNumber10-
multiplierNumber3-

Returns: Series<Number>

Supertrend is a built-in function - you can use it directly. Below is an example implementation:

1 function Supertrend(period = 10, multiplier = 3):
2 basicUpperBand = median + multiplier * ATR(period)
3 basicLowerBand = median - multiplier * ATR(period)
4
5 series finalUpperBand:
6 once: basicUpperBand
7 then: basicUpperBand if basicUpperBand < finalUpperBand[1] or close[1] > finalUpperBand[1] else finalUpperBand[1]
8
9 series finalLowerBand:
10 once: basicLowerBand
11 then: basicLowerBand if basicLowerBand > finalLowerBand[1] or close[1] < finalLowerBand[1] else finalLowerBand[1]
12
13 finalUpperBand if close <= finalUpperBand else finalLowerBand