2023-06-01 09:31:12 +00:00
|
|
|
package indicator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/c9s/bbgo/pkg/datatype/floats"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PivotHighStream struct {
|
2023-06-09 05:18:08 +00:00
|
|
|
*Float64Series
|
2023-06-01 09:31:12 +00:00
|
|
|
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
|
|
|
|
}
|