mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
indicator/pivotlow: drop the legacy CalculateAndUpdate
This commit is contained in:
parent
0df321c880
commit
16c62eab2b
|
@ -22,12 +22,6 @@ type KLinePusher interface {
|
||||||
PushK(k types.KLine)
|
PushK(k types.KLine)
|
||||||
}
|
}
|
||||||
|
|
||||||
// KLineLoader provides an interface for API user to load history klines to the indicator.
|
|
||||||
// The indicator implements its own way to calculate the values from the given history kline array.
|
|
||||||
type KLineLoader interface {
|
|
||||||
LoadK(allKLines []types.KLine)
|
|
||||||
}
|
|
||||||
|
|
||||||
type KLineCalculateUpdater interface {
|
type KLineCalculateUpdater interface {
|
||||||
CalculateAndUpdate(allKLines []types.KLine)
|
CalculateAndUpdate(allKLines []types.KLine)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,6 @@ import (
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//go:generate callbackgen -type PivotLow
|
//go:generate callbackgen -type PivotLow
|
||||||
type PivotLow struct {
|
type PivotLow struct {
|
||||||
types.IntervalWindow
|
types.IntervalWindow
|
||||||
|
@ -55,37 +53,6 @@ func (inc *PivotLow) PushK(k types.KLine) {
|
||||||
inc.EmitUpdate(inc.Last())
|
inc.EmitUpdate(inc.Last())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (inc *PivotLow) LoadK(allKLines []types.KLine) {
|
|
||||||
for _, k := range allKLines {
|
|
||||||
inc.PushK(k)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (inc *PivotLow) CalculateAndUpdate(allKLines []types.KLine) {
|
|
||||||
if len(inc.Values) == 0 {
|
|
||||||
for _, k := range allKLines {
|
|
||||||
inc.PushK(k)
|
|
||||||
}
|
|
||||||
inc.EmitUpdate(inc.Last())
|
|
||||||
} else {
|
|
||||||
k := allKLines[len(allKLines)-1]
|
|
||||||
inc.PushK(k)
|
|
||||||
inc.EmitUpdate(inc.Last())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (inc *PivotLow) handleKLineWindowUpdate(interval types.Interval, window types.KLineWindow) {
|
|
||||||
if inc.Interval != interval {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
inc.CalculateAndUpdate(window)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (inc *PivotLow) Bind(updater KLineWindowUpdater) {
|
|
||||||
updater.OnKLineWindowUpdate(inc.handleKLineWindowUpdate)
|
|
||||||
}
|
|
||||||
|
|
||||||
func calculatePivotLow(lows types.Float64Slice, window int) (float64, error) {
|
func calculatePivotLow(lows types.Float64Slice, window int) (float64, error) {
|
||||||
length := len(lows)
|
length := len(lows)
|
||||||
if length == 0 || length < window {
|
if length == 0 || length < window {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user