Skip to content

Commit

Permalink
Changing RSI to use RMA indicator.
Browse files Browse the repository at this point in the history
Fixes #68.
  • Loading branch information
cinar committed Apr 30, 2022
1 parent 7101edb commit 41f742d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions momentum_indicators.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func Rsi(closing []float64) ([]float64, []float64) {
}
}

meanGains := Sma(14, gains)
meanLosses := Sma(14, losses)
meanGains := Rma(14, gains)
meanLosses := Rma(14, losses)

rsi := make([]float64, len(closing))
rs := make([]float64, len(closing))
Expand Down
36 changes: 32 additions & 4 deletions trend_indicators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,40 @@ func TestKdj(t *testing.T) {
}

func TestRma(t *testing.T) {
values := []float64{2, 4, 6, 8, 10, 12}
expected := []float64{2, 3, 4, 5, 6.25, 7.69}
period := 4
values := []float64{
0,
0.00005,
0.000017,
0.000262,
0.000107,
0,
0,
0.000597,
0,
0,
0.000059,
0.000198,
0.000073,
0,
0.000006,
0,
0.000077,
0.000032,
0.000112,
}

expected := []float64{
0.00009735714286,
0.00009083163265,
0.00008434365889,
0.00008381911183,
0.0000801177467,
0.00008239505051,
}
period := 14

actual := Rma(period, values)
testEquals(t, roundDigitsAll(actual, 2), expected)
testEquals(t, roundDigitsAll(actual[len(actual)-6:], 14), expected)
}

func TestSma(t *testing.T) {
Expand Down

0 comments on commit 41f742d

Please sign in to comment.