From 0b07fb5a830839976fbe7b3f6de13cdc44569df3 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 14 Jul 2022 10:36:16 +0800 Subject: [PATCH] indicator/macd: drop the legacy func calculateMACD --- pkg/indicator/macd.go | 9 --------- pkg/indicator/macd_test.go | 5 +++-- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/pkg/indicator/macd.go b/pkg/indicator/macd.go index 9a50d8b049..972164b50b 100644 --- a/pkg/indicator/macd.go +++ b/pkg/indicator/macd.go @@ -51,15 +51,6 @@ func (inc *MACD) Update(x float64) { inc.Histogram.Push(macd - inc.SignalLine.Last()) } -// Deprecated -- this function is not used ??? ask @narumi -func (inc *MACD) calculateMACD(kLines []types.KLine, priceF KLinePriceMapper) float64 { - for _, k := range kLines { - inc.PushK(k) - } - - return inc.Values[len(inc.Values)-1] -} - func (inc *MACD) Last() float64 { if len(inc.Values) == 0 { return 0.0 diff --git a/pkg/indicator/macd_test.go b/pkg/indicator/macd_test.go index 6cf074fff6..0088f9db92 100644 --- a/pkg/indicator/macd_test.go +++ b/pkg/indicator/macd_test.go @@ -41,8 +41,9 @@ func Test_calculateMACD(t *testing.T) { t.Run(tt.name, func(t *testing.T) { iw := types.IntervalWindow{Window: 9} macd := MACD{IntervalWindow: iw, ShortPeriod: 12, LongPeriod: 26} - priceF := KLineClosePriceMapper - got := macd.calculateMACD(tt.kLines, priceF) + macd.CalculateAndUpdate(tt.kLines) + + got := macd.Last() diff := math.Trunc((got-tt.want)*100) / 100 if diff != 0 { t.Errorf("calculateMACD() = %v, want %v", got, tt.want)