diff --git a/pkg/indicator/rsi.go b/pkg/indicator/rsi.go index 0e8d3b5a6..426dc8309 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 { diffValues := inc.Prices.Diff() - avgGain = diffValues.PositiveValues().AbsoluteValues().Sum() / float64(inc.Window) - avgLoss = diffValues.NegativeValues().AbsoluteValues().Sum() / float64(inc.Window) + avgGain = diffValues.PositiveValuesOrZero().AbsoluteValues().Sum() / float64(inc.Window) + avgLoss = diffValues.NegativeValuesOrZero().AbsoluteValues().Sum() / float64(inc.Window) } else { diff := price - inc.Prices[len(inc.Prices)-2] currentGain := math.Max(diff, 0) diff --git a/pkg/types/float_slice.go b/pkg/types/float_slice.go index d82877235..8b11aabc6 100644 --- a/pkg/types/float_slice.go +++ b/pkg/types/float_slice.go @@ -66,7 +66,7 @@ func (s Float64Slice) Diff() Float64Slice { return values } -func (s Float64Slice) PositiveValues() Float64Slice { +func (s Float64Slice) PositiveValuesOrZero() Float64Slice { var values Float64Slice for _, v := range s { values.Push(math.Max(v, 0)) @@ -74,7 +74,7 @@ func (s Float64Slice) PositiveValues() Float64Slice { return values } -func (s Float64Slice) NegativeValues() Float64Slice { +func (s Float64Slice) NegativeValuesOrZero() Float64Slice { var values Float64Slice for _, v := range s { values.Push(math.Min(v, 0))