diff --git a/pkg/indicator/rsi.go b/pkg/indicator/rsi.go index 33e50d5e1..8cc8dd3a2 100644 --- a/pkg/indicator/rsi.go +++ b/pkg/indicator/rsi.go @@ -37,8 +37,8 @@ func (inc *RSI) Update(kline types.KLine, priceF KLinePriceMapper) { if len(inc.Prices) == inc.Window+1 { priceDifferences := inc.Prices.Diff() - avgGain = priceDifferences.PositiveValuesOrZero().AbsoluteValues().Sum() / float64(inc.Window) - avgLoss = priceDifferences.NegativeValuesOrZero().AbsoluteValues().Sum() / float64(inc.Window) + avgGain = priceDifferences.PositiveValuesOrZero().Abs().Sum() / float64(inc.Window) + avgLoss = priceDifferences.NegativeValuesOrZero().Abs().Sum() / float64(inc.Window) } else { difference := price - inc.Prices[len(inc.Prices)-2] currentGain := math.Max(difference, 0) diff --git a/pkg/types/float_slice.go b/pkg/types/float_slice.go index 9974adb62..fd1312d69 100644 --- a/pkg/types/float_slice.go +++ b/pkg/types/float_slice.go @@ -76,7 +76,7 @@ func (s Float64Slice) NegativeValuesOrZero() (values Float64Slice) { return values } -func (s Float64Slice) AbsoluteValues() (values Float64Slice) { +func (s Float64Slice) Abs() (values Float64Slice) { for _, v := range s { values.Push(math.Abs(v)) } @@ -113,6 +113,6 @@ func (s Float64Slice) Dot(other Float64Slice) float64 { return floats.Dot(s, other) } -func (s Float64Slice) Normalize() (values Float64Slice) { +func (s Float64Slice) Normalize() Float64Slice { return s.DivScalar(s.Sum()) }