From e529a3271d87b3abcb0ed369c5a527751af5460a Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 12 Jun 2023 17:38:17 +0800 Subject: [PATCH] indicator: fix ewma2 initial value --- pkg/indicator/v2_ewma.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/indicator/v2_ewma.go b/pkg/indicator/v2_ewma.go index 45a15d7ca..16feb9901 100644 --- a/pkg/indicator/v2_ewma.go +++ b/pkg/indicator/v2_ewma.go @@ -19,6 +19,10 @@ func EWMA2(source Float64Source, window int) *EWMAStream { func (s *EWMAStream) Calculate(v float64) float64 { last := s.slice.Last(0) + if last == 0.0 { + return v + } + m := s.multiplier return (1.0-m)*last + m*v }