bbgo: add strict condition for CumulatedVolumeTakeProfit

This commit is contained in:
c9s 2022-09-14 12:04:12 +08:00
parent 402ac58b53
commit d022c80727
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -38,6 +38,7 @@ func (s *CumulatedVolumeTakeProfit) Bind(session *ExchangeSession, orderExecutor
session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, s.Interval, func(kline types.KLine) {
closePrice := kline.Close
openPrice := kline.Open
if position.IsClosed() || position.IsDust(closePrice) {
return
}
@ -65,7 +66,21 @@ func (s *CumulatedVolumeTakeProfit) Bind(session *ExchangeSession, orderExecutor
cbv = cbv.Add(last.Volume)
}
if cqv.Compare(s.MinQuoteVolume) > 0 {
if cqv.Compare(s.MinQuoteVolume) < 0 {
return
}
// If the closed price is below the open price, it means the sell taker is still strong.
if closePrice.Compare(openPrice) < 0 {
log.Infof("[CumulatedVolumeTakeProfit] closePrice %f is below openPrice %f, skip taking profit", closePrice.Float64(), openPrice.Float64())
return
}
kline.GetUpperShadowHeight()
if kline.High.Sub(closePrice).Compare(closePrice.Sub(kline.Low)) < 0 {
}
Notify("[CumulatedVolumeTakeProfit] %s TakeProfit triggered by cumulated volume (window: %d) %f > %f, price = %f",
position.Symbol,
s.Window,
@ -75,7 +90,5 @@ func (s *CumulatedVolumeTakeProfit) Bind(session *ExchangeSession, orderExecutor
if err := orderExecutor.ClosePosition(context.Background(), fixedpoint.One, "cumulatedVolumeTakeProfit"); err != nil {
log.WithError(err).Errorf("close position error")
}
return
}
}))
}