From 42d6bf03b555a4abbf31766d7a95b1d8c673563b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=82=8B=E3=81=BF?= Date: Tue, 29 Mar 2022 02:23:42 +0800 Subject: [PATCH] Rename functions --- pkg/indicator/rsi.go | 4 ++-- pkg/types/float_slice.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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))