2023-05-26 06:31:06 +00:00
|
|
|
package indicator
|
|
|
|
|
2023-05-30 03:35:24 +00:00
|
|
|
import (
|
|
|
|
"github.com/c9s/bbgo/pkg/datatype/floats"
|
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
|
|
|
)
|
|
|
|
|
2023-05-26 06:31:06 +00:00
|
|
|
//go:generate callbackgen -type Float64Updater
|
|
|
|
type Float64Updater struct {
|
|
|
|
updateCallbacks []func(v float64)
|
2023-05-30 03:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Float64Series struct {
|
|
|
|
types.SeriesBase
|
|
|
|
Float64Updater
|
2023-05-30 04:13:55 +00:00
|
|
|
slice floats.Slice
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewFloat64Series(v ...float64) Float64Series {
|
|
|
|
s := Float64Series{}
|
|
|
|
s.slice = v
|
|
|
|
s.SeriesBase.Series = s.slice
|
|
|
|
return s
|
2023-05-30 03:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Float64Series) Last() float64 {
|
|
|
|
return f.slice.Last()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Float64Series) Index(i int) float64 {
|
|
|
|
length := len(f.slice)
|
|
|
|
if length == 0 || length-i-1 < 0 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return f.slice[length-i-1]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Float64Series) Length() int {
|
|
|
|
return len(f.slice)
|
2023-05-26 06:31:06 +00:00
|
|
|
}
|