mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
Merge pull request #1356 from c9s/c9s/fix-rma-zero-value-issue
FIX: fix rma zero value issue
This commit is contained in:
commit
3fcc21c1f1
|
@ -48,11 +48,6 @@ func (s *RMAStream) Calculate(x float64) float64 {
|
||||||
}
|
}
|
||||||
s.counter++
|
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.Slice.Push(tmp)
|
||||||
s.previous = tmp
|
s.previous = tmp
|
||||||
return tmp
|
return tmp
|
||||||
|
|
|
@ -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)
|
// 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
|
// A Float64Calculator should be able to calculate the float64 result from a single float64 argument input
|
||||||
func (f *Float64Series) Bind(source Float64Source, target Float64Calculator) {
|
func (f *Float64Series) Bind(source Float64Source, target Float64Calculator) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user