diff --git a/pkg/bbgo/standard_indicator_set.go b/pkg/bbgo/standard_indicator_set.go index 6f94d7c07..09ef5d082 100644 --- a/pkg/bbgo/standard_indicator_set.go +++ b/pkg/bbgo/standard_indicator_set.go @@ -74,6 +74,13 @@ func (s *StandardIndicatorSet) EWMA(iw types.IntervalWindow) *indicator.EWMA { return inc.(*indicator.EWMA) } +// VWMA +func (s *StandardIndicatorSet) VWMA(iw types.IntervalWindow) *indicator.VWMA { + inc := s.allocateSimpleIndicator(&indicator.VWMA{IntervalWindow: iw}, iw) + return inc.(*indicator.VWMA) +} + + func (s *StandardIndicatorSet) PivotLow(iw types.IntervalWindow) *indicator.PivotLow { inc := s.allocateSimpleIndicator(&indicator.PivotLow{IntervalWindow: iw}, iw) return inc.(*indicator.PivotLow) diff --git a/pkg/indicator/vwma.go b/pkg/indicator/vwma.go index 08e45f4b2..263c5fb5a 100644 --- a/pkg/indicator/vwma.go +++ b/pkg/indicator/vwma.go @@ -70,6 +70,15 @@ func (inc *VWMA) Update(price, volume float64) { inc.Values.Push(vwma) } +func (inc *VWMA) PushK(k types.KLine) { + if inc.EndTime != zeroTime && k.EndTime.Before(inc.EndTime) { + return + } + + inc.Update(k.Close.Float64(), k.Volume.Float64()) +} + + func (inc *VWMA) CalculateAndUpdate(allKLines []types.KLine) { if len(allKLines) < inc.Window { return