pivotshort: use bbgo notify instead of just info log

This commit is contained in:
c9s 2022-07-30 18:14:53 +08:00
parent 8873101752
commit 55a128ea90
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 9 additions and 5 deletions

View File

@ -173,25 +173,25 @@ func (s *BreakLow) Bind(session *bbgo.ExchangeSession, orderExecutor *bbgo.Gener
// force direction to be down // force direction to be down
if closePrice.Compare(openPrice) >= 0 { if closePrice.Compare(openPrice) >= 0 {
log.Infof("%s price %f is closed higher than the open price %f, skip this break", kline.Symbol, closePrice.Float64(), openPrice.Float64()) bbgo.Notify("%s price %f is closed higher than the open price %f, skip this break", kline.Symbol, closePrice.Float64(), openPrice.Float64())
// skip UP klines // skip UP klines
return return
} }
log.Infof("%s breakLow signal detected, closed price %f < breakPrice %f", kline.Symbol, closePrice.Float64(), breakPrice.Float64()) bbgo.Notify("%s breakLow signal detected, closed price %f < breakPrice %f", kline.Symbol, closePrice.Float64(), breakPrice.Float64())
if s.lastBreakLow.IsZero() || previousLow.Compare(s.lastBreakLow) < 0 { if s.lastBreakLow.IsZero() || previousLow.Compare(s.lastBreakLow) < 0 {
s.lastBreakLow = previousLow s.lastBreakLow = previousLow
} }
if position.IsOpened(kline.Close) { if position.IsOpened(kline.Close) {
log.Infof("position is already opened, skip short") bbgo.Notify("position is already opened, skip")
return return
} }
// trend EMA protection // trend EMA protection
if s.TrendEMA != nil && !s.TrendEMA.GradientAllowed() { if s.TrendEMA != nil && !s.TrendEMA.GradientAllowed() {
log.Infof("trendEMA protection: close price %f", kline.Close.Float64()) bbgo.Notify("trendEMA protection: close price %f, gradient %f", kline.Close.Float64(), s.TrendEMA.Gradient())
return return
} }
@ -205,7 +205,7 @@ func (s *BreakLow) Bind(session *bbgo.ExchangeSession, orderExecutor *bbgo.Gener
emaStopShortPrice := ema.Mul(fixedpoint.One.Sub(s.StopEMA.Range)) emaStopShortPrice := ema.Mul(fixedpoint.One.Sub(s.StopEMA.Range))
if closePrice.Compare(emaStopShortPrice) < 0 { if closePrice.Compare(emaStopShortPrice) < 0 {
log.Infof("stopEMA protection: close price %f < EMA(%v %f) * (1 - RANGE %f) = %f", closePrice.Float64(), s.StopEMA, ema.Float64(), s.StopEMA.Range.Float64(), emaStopShortPrice.Float64()) bbgo.Notify("stopEMA protection: close price %f < EMA(%v %f) * (1 - RANGE %f) = %f", closePrice.Float64(), s.StopEMA, ema.Float64(), s.StopEMA.Range.Float64(), emaStopShortPrice.Float64())
return return
} }
} }

View File

@ -27,6 +27,10 @@ func (s *TrendEMA) Bind(session *bbgo.ExchangeSession, orderExecutor *bbgo.Gener
})) }))
} }
func (s *TrendEMA) Gradient() float64 {
return s.trendGradient
}
func (s *TrendEMA) GradientAllowed() bool { func (s *TrendEMA) GradientAllowed() bool {
if s.trendEWMALast > 0.0 && s.trendEWMACurrent > 0.0 { if s.trendEWMALast > 0.0 && s.trendEWMACurrent > 0.0 {
s.trendGradient = s.trendEWMALast / s.trendEWMACurrent s.trendGradient = s.trendEWMALast / s.trendEWMACurrent