strategy/linregmaker: add more trend reverse logs

This commit is contained in:
Andy Cheng 2022-12-13 11:06:18 +08:00
parent a6956e50b7
commit 79dcda5f52
2 changed files with 6 additions and 5 deletions

View File

@ -18,8 +18,8 @@ backtest:
# for testing max draw down (MDD) at 03-12
# see here for more details
# https://www.investopedia.com/terms/m/maximum-drawdown-mdd.asp
startTime: "2022-05-01"
endTime: "2022-10-31"
startTime: "2022-03-15"
endTime: "2022-03-23"
symbols:
- BTCUSDT
accounts:
@ -41,7 +41,7 @@ exchangeStrategies:
# reverseEMA
reverseEMA:
interval: 1d
window: 5
window: 60
# reverseInterval
reverseInterval: 4h

View File

@ -657,12 +657,13 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
// Trend reversal
if s.mainTrendCurrent != s.mainTrendPrevious {
log.Infof("%s trend reverse to %v", s.Symbol, s.mainTrendCurrent)
// Close on-hand position that is not in the same direction as the new trend
if !s.Position.IsDust(closePrice) &&
((s.Position.IsLong() && s.mainTrendCurrent == types.DirectionDown) ||
(s.Position.IsShort() && s.mainTrendCurrent == types.DirectionUp)) {
log.Infof("%s trend reverse to %v. closing on-hand position", s.Symbol, s.mainTrendCurrent)
bbgo.Notify("%s trend reverse to %v. closing on-hand position", s.Symbol, s.mainTrendCurrent)
log.Infof("%s closing on-hand position due to trend reverse", s.Symbol)
bbgo.Notify("%s closing on-hand position due to trend reverse", s.Symbol)
if err := s.ClosePosition(ctx, fixedpoint.One); err != nil {
log.WithError(err).Errorf("cannot close on-hand position of %s", s.Symbol)
bbgo.Notify("cannot close on-hand position of %s", s.Symbol)