mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
52 lines
901 B
Go
52 lines
901 B
Go
package drift
|
|
|
|
import (
|
|
"github.com/c9s/bbgo/pkg/indicator"
|
|
"github.com/c9s/bbgo/pkg/types"
|
|
)
|
|
|
|
type DriftMA struct {
|
|
types.SeriesBase
|
|
ma1 types.UpdatableSeriesExtend
|
|
drift *indicator.Drift
|
|
ma2 types.UpdatableSeriesExtend
|
|
}
|
|
|
|
func (s *DriftMA) Update(value float64) {
|
|
s.ma1.Update(value)
|
|
s.drift.Update(s.ma1.Last())
|
|
s.ma2.Update(s.drift.Last())
|
|
}
|
|
|
|
func (s *DriftMA) Last() float64 {
|
|
return s.ma2.Last()
|
|
}
|
|
|
|
func (s *DriftMA) Index(i int) float64 {
|
|
return s.ma2.Index(i)
|
|
}
|
|
|
|
func (s *DriftMA) Length() int {
|
|
return s.ma2.Length()
|
|
}
|
|
|
|
func (s *DriftMA) ZeroPoint() float64 {
|
|
return s.drift.ZeroPoint()
|
|
}
|
|
|
|
func (s *DriftMA) Clone() *DriftMA {
|
|
out := DriftMA{
|
|
ma1: types.Clone(s.ma1),
|
|
drift: s.drift.Clone(),
|
|
ma2: types.Clone(s.ma2),
|
|
}
|
|
out.SeriesBase.Series = &out
|
|
return &out
|
|
}
|
|
|
|
func (s *DriftMA) TestUpdate(v float64) *DriftMA {
|
|
out := s.Clone()
|
|
out.Update(v)
|
|
return out
|
|
}
|