Skip to content

Commit

Permalink
bbgo: update VWMA and add VWMA to the indicator method
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Aug 24, 2022
1 parent 469c6bf commit 09cc91b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/bbgo/standard_indicator_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions pkg/indicator/vwma.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 09cc91b

Please sign in to comment.