content/flux/v0/stdlib/universe/relativestrengthindex.md
relativeStrengthIndex() measures the relative speed and change of values in input tables.
RSI = 100 - (100 / (1 + (AVG GAIN / AVG LOSS))).AVG GAIN and AVG LOSS are averages of the n period.AVG GAIN = ((PREVIOUS AVG GAIN) * (n - 1)) / nAVG LOSS = ((PREVIOUS AVG LOSS) * (n - 1)) / nrelativeStrengthIndex() ignores null values.For each input table with x rows, relativeStrengthIndex() outputs a table
with x - n rows.
(<-tables: stream[A], n: int, ?columns: [string]) => stream[B] where A: Record, B: Record
{{% caption %}} For more information, see Function type signatures. {{% /caption %}}
({{< req >}}) Number of values to use to calculate the RSI.
Columns to operate on. Default is ["_value"].
Input data. Default is piped-forward data (<-).
import "sampledata"
sampledata.int()
|> relativeStrengthIndex(n: 3)
{{< expand-wrapper >}} {{% expand "View example input and output" %}}
| _time | _value | *tag |
|---|---|---|
| 2021-01-01T00:00:00Z | -2 | t1 |
| 2021-01-01T00:00:10Z | 10 | t1 |
| 2021-01-01T00:00:20Z | 7 | t1 |
| 2021-01-01T00:00:30Z | 17 | t1 |
| 2021-01-01T00:00:40Z | 15 | t1 |
| 2021-01-01T00:00:50Z | 4 | t1 |
| _time | _value | *tag |
|---|---|---|
| 2021-01-01T00:00:00Z | 19 | t2 |
| 2021-01-01T00:00:10Z | 4 | t2 |
| 2021-01-01T00:00:20Z | -3 | t2 |
| 2021-01-01T00:00:30Z | 19 | t2 |
| 2021-01-01T00:00:40Z | 13 | t2 |
| 2021-01-01T00:00:50Z | 1 | t2 |
| _time | _value | *tag |
|---|---|---|
| 2021-01-01T00:00:30Z | 84.375 | t1 |
| 2021-01-01T00:00:40Z | 73.97260273972603 | t1 |
| 2021-01-01T00:00:50Z | 36.672325976230894 | t1 |
| _time | _value | *tag |
|---|---|---|
| 2021-01-01T00:00:30Z | 70.27027027027026 | t2 |
| 2021-01-01T00:00:40Z | 59.42857142857142 | t2 |
| 2021-01-01T00:00:50Z | 40.625 | t2 |
{{% /expand %}} {{< /expand-wrapper >}}