3.6 KiB
3.6 KiB
title | description | menu | weight | flux/v0/tags | introduced | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
relativeStrengthIndex() function | `relativeStrengthIndex()` measures the relative speed and change of values in input tables. |
|
101 |
|
0.38.0 |
relativeStrengthIndex()
measures the relative speed and change of values in input tables.
Relative strength index (RSI) 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
andAVG LOSS
are averages of then
period. - For subsequent calculations:
AVG GAIN
=((PREVIOUS AVG GAIN) * (n - 1)) / n
AVG LOSS
=((PREVIOUS AVG LOSS) * (n - 1)) / n
relativeStrengthIndex()
ignoresnull
values.
Output tables
For each input table with x
rows, relativeStrengthIndex()
outputs a table
with x - n
rows.
Function type signature
(<-tables: stream[A], n: int, ?columns: [string]) => stream[B] where A: Record, B: Record
{{% caption %}} For more information, see Function type signatures. {{% /caption %}}
Parameters
n
({{< req >}}) Number of values to use to calculate the RSI.
columns
Columns to operate on. Default is ["_value"]
.
tables
Input data. Default is piped-forward data (<-
).
Examples
Calculate a three point relative strength index
import "sampledata"
sampledata.int()
|> relativeStrengthIndex(n: 3)
{{< expand-wrapper >}} {{% expand "View example input and output" %}}
Input data
_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 |
Output data
_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 >}}