From aa492a05a1cb8244eea02043805691e49527e27f Mon Sep 17 00:00:00 2001 From: Andy Cheng Date: Fri, 7 Oct 2022 13:48:16 +0800 Subject: [PATCH] fix/supertrend-strategy: LinReg baseline slope wrongly calculated as reciprocal --- pkg/strategy/supertrend/linreg.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/strategy/supertrend/linreg.go b/pkg/strategy/supertrend/linreg.go index 0ead276e1..eb47c2c7b 100644 --- a/pkg/strategy/supertrend/linreg.go +++ b/pkg/strategy/supertrend/linreg.go @@ -13,8 +13,8 @@ type LinReg struct { types.SeriesBase types.IntervalWindow // Values are the slopes of linear regression baseline - Values floats.Slice - klines types.KLineWindow + Values floats.Slice + klines types.KLineWindow EndTime time.Time } @@ -66,7 +66,7 @@ func (lr *LinReg) Update(kline types.KLine) { average := sumY / length endPrice := average - slope*sumX/length + slope startPrice := endPrice + slope*(length-1) - lr.Values.Push((length - 1) / (endPrice - startPrice)) + lr.Values.Push((endPrice - startPrice) / (length - 1)) log.Debugf("linear regression baseline slope: %f", lr.Last()) }