relativeStrengthIndex() function

The relativeStrengthIndex() function measures the relative speed and change of values in an input table.

*Function type: Transformation*

  1. relativeStrengthIndex(
  2. n: 5,
  3. columns: ["_value"]
  4. )
Relative strength index rules
  • The general equation for calculating a relative strength index (RSI) is RSI = 100 - (100 / (1 + (AVG GAIN / AVG LOSS))).
  • For the first value of the RSI, AVG GAIN and AVG LOSS are averages of the n period.
  • For subsequent calculations:
    • AVG GAIN = ((PREVIOUS AVG GAIN) * (n - 1)) / n
    • AVG LOSS = ((PREVIOUS AVG LOSS) * (n - 1)) / n
  • relativeStrengthIndex() ignores null values.

Parameters

n

The number of values to use to calculate the RSI.

*Data type: Integer*

columns

Columns to operate on. Defaults to ["_value"].

*Data type: Array of Strings*

Output tables

For each input table with x rows, relativeStrengthIndex() outputs a table with x - n rows.

Examples

Calculate a five point relative strength index

  1. from(bucket: "example-bucket"):
  2. |> range(start: -12h)
  3. |> relativeStrengthIndex(n: 5)

Table transformation with a ten point RSI

Input table:
_timeABtag
000111tv
000222tv
000333tv
000444tv
000555tv
000666tv
000777tv
000888tv
000999tv
00101010tv
00111111tv
00121212tv
00131313tv
00141414tv
00151515tv
00161616tv
001717nulltv
00181817tv
Query:
  1. // ...
  2. |> relativeStrengthIndex(
  3. n: 10,
  4. columns: ["A", "B"]
  5. )
Output table:
_timeABtag
0011100100tv
0012100100tv
0013100100tv
0014100100tv
0015100100tv
00169090tv
00178190tv
001872.981tv

Related articles