indicator: add pivothigh v2 indicator

This commit is contained in:
c9s 2023-06-01 17:31:12 +08:00
parent 9a486388fa
commit 15d1caef31
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 28 additions and 3 deletions

View File

@ -0,0 +1,27 @@
package indicator
import (
"github.com/c9s/bbgo/pkg/datatype/floats"
)
type PivotHighStream struct {
Float64Series
rawValues floats.Slice
window, rightWindow int
}
func PivotHigh2(source Float64Source, window, rightWindow int) *PivotHighStream {
s := &PivotHighStream{
Float64Series: NewFloat64Series(),
window: window,
rightWindow: rightWindow,
}
s.Subscribe(source, func(x float64) {
s.rawValues.Push(x)
if low, ok := calculatePivotHigh(s.rawValues, s.window, s.rightWindow); ok {
s.PushAndEmit(low)
}
})
return s
}

View File

@ -6,9 +6,7 @@ import (
type PivotLowStream struct {
Float64Series
rawValues floats.Slice
rawValues floats.Slice
window, rightWindow int
}