indicator: fix ewma2 initial value

This commit is contained in:
c9s 2023-06-12 17:38:17 +08:00
parent 0a5f31a80f
commit e529a3271d
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -19,6 +19,10 @@ func EWMA2(source Float64Source, window int) *EWMAStream {
func (s *EWMAStream) Calculate(v float64) float64 { func (s *EWMAStream) Calculate(v float64) float64 {
last := s.slice.Last(0) last := s.slice.Last(0)
if last == 0.0 {
return v
}
m := s.multiplier m := s.multiplier
return (1.0-m)*last + m*v return (1.0-m)*last + m*v
} }