Documentation

relativeStrengthIndex() function

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

Function type: Transformation

relativeStrengthIndex(
  n: 5,
  columns: ["_value"]
)
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

from(bucket: "example-bucket"):
  |> range(start: -12h)
  |> 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:
// ...
  |> relativeStrengthIndex(
    n: 10,
    columns: ["A", "B"]
  )
Output table:
_timeABtag
0011100100tv
0012100100tv
0013100100tv
0014100100tv
0015100100tv
00169090tv
00178190tv
001872.981tv

New! Cloud or OSS?

InfluxDB OSS 2.0 now generally available!

InfluxDB OSS 2.0 is now generally available and ready for production use. See the InfluxDB OSS 2.0 release notes.

For information about upgrading to InfluxDB OSS 2.0, see: