From a9d9ef379268f6f1a841d3626a73d89612097276 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 24 Oct 2023 13:44:25 +0800 Subject: [PATCH 1/2] Add AddSubscriber method on Float64Series --- pkg/types/series_float64.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/types/series_float64.go b/pkg/types/series_float64.go index f12e05d58..8c07b4a13 100644 --- a/pkg/types/series_float64.go +++ b/pkg/types/series_float64.go @@ -46,6 +46,21 @@ func (f *Float64Series) Subscribe(source Float64Source, c func(x float64)) { } } +// AddSubscriber adds the subscriber function and push historical data to the subscriber +func (f *Float64Series) AddSubscriber(fn func(v float64)) { + f.OnUpdate(fn) + + if f.Length() == 0 { + return + } + + // push historical values to the subscriber + for _, vv := range f.Slice { + fn(vv) + } +} + + // Bind binds the source event to the target (Float64Calculator) // A Float64Calculator should be able to calculate the float64 result from a single float64 argument input func (f *Float64Series) Bind(source Float64Source, target Float64Calculator) { From 4c1654652eb20eec8237e51b0c7c92fc3e921524 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 24 Oct 2023 13:44:49 +0800 Subject: [PATCH 2/2] indicator: remove unnecessary zero value push --- pkg/indicator/v2/rma.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pkg/indicator/v2/rma.go b/pkg/indicator/v2/rma.go index 1aa08ccdc..4a6c8b327 100644 --- a/pkg/indicator/v2/rma.go +++ b/pkg/indicator/v2/rma.go @@ -48,11 +48,6 @@ func (s *RMAStream) Calculate(x float64) float64 { } s.counter++ - if s.counter < s.window { - // we can use x, but we need to use 0. to make the same behavior as the result from python pandas_ta - s.Slice.Push(0) - } - s.Slice.Push(tmp) s.previous = tmp return tmp