mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
xmaker: update signal conditions to metrics
This commit is contained in:
parent
b8abc065de
commit
371db8e7d1
|
@ -63,15 +63,14 @@ func (s *BollingerBandTrendSignal) CalculateSignal(ctx context.Context) (float64
|
|||
lastDownBand := fixedpoint.NewFromFloat(s.indicator.DownBand.Last(0))
|
||||
lastUpBand := fixedpoint.NewFromFloat(s.indicator.UpBand.Last(0))
|
||||
|
||||
// if the price is inside the band, do not vote
|
||||
if closePrice.Compare(lastDownBand) > 0 && closePrice.Compare(lastUpBand) < 0 {
|
||||
return 0.0, nil
|
||||
}
|
||||
|
||||
maxBandWidth := s.indicator.StdDev.Last(0) * s.MaxBandWidth
|
||||
|
||||
signal := 0.0
|
||||
if closePrice.Compare(lastDownBand) < 0 {
|
||||
|
||||
// if the price is inside the band, do not vote
|
||||
if closePrice.Compare(lastDownBand) > 0 && closePrice.Compare(lastUpBand) < 0 {
|
||||
signal = 0.0
|
||||
} else if closePrice.Compare(lastDownBand) < 0 {
|
||||
signal = lastDownBand.Sub(closePrice).Float64() / maxBandWidth * -2.0
|
||||
} else if closePrice.Compare(lastUpBand) > 0 {
|
||||
signal = closePrice.Sub(lastUpBand).Float64() / maxBandWidth * 2.0
|
||||
|
@ -82,5 +81,7 @@ func (s *BollingerBandTrendSignal) CalculateSignal(ctx context.Context) (float64
|
|||
lastUpBand.Float64(),
|
||||
lastDownBand.Float64(),
|
||||
closePrice.Float64())
|
||||
|
||||
bollingerBandSignalMetrics.WithLabelValues(s.symbol).Set(signal)
|
||||
return signal, nil
|
||||
}
|
||||
|
|
|
@ -45,17 +45,15 @@ func (s *OrderBookBestPriceVolumeSignal) CalculateSignal(ctx context.Context) (f
|
|||
return 0.0, nil
|
||||
}
|
||||
|
||||
if bid.Volume.Compare(s.MinVolume) < 0 && ask.Volume.Compare(s.MinVolume) < 0 {
|
||||
return 0.0, nil
|
||||
}
|
||||
|
||||
// TODO: may use scale to define this
|
||||
sumVol := bid.Volume.Add(ask.Volume)
|
||||
bidRatio := bid.Volume.Div(sumVol)
|
||||
askRatio := ask.Volume.Div(sumVol)
|
||||
denominator := fixedpoint.One.Sub(s.RatioThreshold)
|
||||
signal := 0.0
|
||||
if bidRatio.Compare(s.RatioThreshold) >= 0 {
|
||||
if bid.Volume.Compare(s.MinVolume) < 0 && ask.Volume.Compare(s.MinVolume) < 0 {
|
||||
signal = 0.0
|
||||
} else if bidRatio.Compare(s.RatioThreshold) >= 0 {
|
||||
numerator := bidRatio.Sub(s.RatioThreshold)
|
||||
signal = numerator.Div(denominator).Float64()
|
||||
} else if askRatio.Compare(s.RatioThreshold) >= 0 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user