bbgo: update VWMA and add VWMA to the indicator method

This commit is contained in:
c9s 2022-08-24 17:45:32 +08:00
parent 469c6bfb28
commit 09cc91bab8
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 16 additions and 0 deletions

View File

@ -74,6 +74,13 @@ func (s *StandardIndicatorSet) EWMA(iw types.IntervalWindow) *indicator.EWMA {
return inc.(*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 { func (s *StandardIndicatorSet) PivotLow(iw types.IntervalWindow) *indicator.PivotLow {
inc := s.allocateSimpleIndicator(&indicator.PivotLow{IntervalWindow: iw}, iw) inc := s.allocateSimpleIndicator(&indicator.PivotLow{IntervalWindow: iw}, iw)
return inc.(*indicator.PivotLow) return inc.(*indicator.PivotLow)

View File

@ -70,6 +70,15 @@ func (inc *VWMA) Update(price, volume float64) {
inc.Values.Push(vwma) 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) { func (inc *VWMA) CalculateAndUpdate(allKLines []types.KLine) {
if len(allKLines) < inc.Window { if len(allKLines) < inc.Window {
return return