RSI

Calculates the Relative Strength Index indicator.

Accepts the following parameters:

Parameter NameTypeDefault ValueNotes
applyToSeries<Number>
close
-
periodNumber14-

Returns: Series<Number>

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

1 function RSI(applyTo = close, period = 14):
2 diff = applyTo - applyTo[1]
3 series positive:
4 once: 0 if isknown applyTo else unknown
5 then: (positive[1] * (period - 1) + (diff if diff > 0 else 0)) / period
6
7 series negative:
8 once: 0 if isknown applyTo else unknown
9 then: (negative[1] * (period - 1) + (-diff if diff < 0 else 0)) / period
10
11 unknown if (
12 not isknown applyTo[period]
13 ) else 50 if (
14 positive == 0 and negative == 0
15 ) else 100 if (
16 negative == 0
17 ) else (
18 100 - 100 / (1 + positive / negative)
19 )