mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
pivotshort: adjust shadow ratio calculation
This commit is contained in:
parent
260857b5b1
commit
e575236db8
|
@ -35,11 +35,18 @@ exchangeStrategies:
|
||||||
roiStopLossPercentage: 1%
|
roiStopLossPercentage: 1%
|
||||||
|
|
||||||
# roiTakeProfitPercentage is the take profit percentage of the position ROI (currently the price change)
|
# roiTakeProfitPercentage is the take profit percentage of the position ROI (currently the price change)
|
||||||
|
# force to take the profit ROI exceeded the percentage.
|
||||||
roiTakeProfitPercentage: 25%
|
roiTakeProfitPercentage: 25%
|
||||||
|
|
||||||
# lowerShadowRatio is used to force taking profit when the (lower shadow height / low price) > lowerShadowRatio
|
# lowerShadowRatio is used to force taking profit when the (lower shadow height / low price) > lowerShadowRatio
|
||||||
|
# you can grab a simple stats by the following SQL:
|
||||||
|
# SELECT ((close - low) / close) AS shadow_ratio FROM binance_klines WHERE symbol = 'ETHUSDT' AND `interval` = '5m' AND start_time > '2022-01-01' ORDER BY shadow_ratio DESC LIMIT 20;
|
||||||
lowerShadowRatio: 3%
|
lowerShadowRatio: 3%
|
||||||
|
|
||||||
|
cumulatedVolume:
|
||||||
|
minVolume: 50_000
|
||||||
|
window: 5
|
||||||
|
|
||||||
marginOrderSideEffect: repay
|
marginOrderSideEffect: repay
|
||||||
|
|
||||||
backtest:
|
backtest:
|
||||||
|
|
|
@ -69,6 +69,8 @@ func (b *ActiveOrderBook) waitAllClear(ctx context.Context, waitTime, timeout ti
|
||||||
|
|
||||||
// GracefulCancel cancels the active orders gracefully
|
// GracefulCancel cancels the active orders gracefully
|
||||||
func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange) error {
|
func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange) error {
|
||||||
|
waitTime := CancelOrderWaitTime
|
||||||
|
|
||||||
log.Debugf("[ActiveOrderBook] gracefully cancelling %s orders...", b.Symbol)
|
log.Debugf("[ActiveOrderBook] gracefully cancelling %s orders...", b.Symbol)
|
||||||
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
@ -86,9 +88,9 @@ func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange)
|
||||||
log.WithError(err).Errorf("[ActiveOrderBook] can not cancel %s orders", b.Symbol)
|
log.WithError(err).Errorf("[ActiveOrderBook] can not cancel %s orders", b.Symbol)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("[ActiveOrderBook] waiting %s for %s orders to be cancelled...", CancelOrderWaitTime, b.Symbol)
|
log.Debugf("[ActiveOrderBook] waiting %s for %s orders to be cancelled...", waitTime, b.Symbol)
|
||||||
|
|
||||||
clear, err := b.waitAllClear(ctx, CancelOrderWaitTime, 5*time.Second)
|
clear, err := b.waitAllClear(ctx, waitTime, 5*time.Second)
|
||||||
if clear || err != nil {
|
if clear || err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -298,7 +298,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
} else if roi.Compare(s.Exit.RoiTakeProfitPercentage) > 0 {
|
} else if roi.Compare(s.Exit.RoiTakeProfitPercentage) > 0 { // disable this condition temporarily
|
||||||
s.Notify("%s TakeProfit triggered at price %f, ROI take profit percentage by %s", s.Symbol, kline.Close.Float64(), roi.Percentage(), kline)
|
s.Notify("%s TakeProfit triggered at price %f, ROI take profit percentage by %s", s.Symbol, kline.Close.Float64(), roi.Percentage(), kline)
|
||||||
if err := s.activeMakerOrders.GracefulCancel(ctx, s.session.Exchange); err != nil {
|
if err := s.activeMakerOrders.GracefulCancel(ctx, s.session.Exchange); err != nil {
|
||||||
log.WithError(err).Errorf("graceful cancel order error")
|
log.WithError(err).Errorf("graceful cancel order error")
|
||||||
|
@ -307,8 +307,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
if err := s.ClosePosition(ctx, fixedpoint.One); err != nil {
|
if err := s.ClosePosition(ctx, fixedpoint.One); err != nil {
|
||||||
log.WithError(err).Errorf("close position error")
|
log.WithError(err).Errorf("close position error")
|
||||||
}
|
}
|
||||||
return
|
} else if !s.Exit.LowerShadowRatio.IsZero() && kline.GetLowerShadowHeight().Div(kline.Close).Compare(s.Exit.LowerShadowRatio) > 0 {
|
||||||
} else if !s.Exit.LowerShadowRatio.IsZero() && kline.GetLowerShadowHeight().Div(kline.Low).Compare(s.Exit.LowerShadowRatio) > 0 {
|
|
||||||
s.Notify("%s TakeProfit triggered at price %f: shadow ratio %f", s.Symbol, kline.Close.Float64(), kline.GetLowerShadowRatio().Float64(), kline)
|
s.Notify("%s TakeProfit triggered at price %f: shadow ratio %f", s.Symbol, kline.Close.Float64(), kline.GetLowerShadowRatio().Float64(), kline)
|
||||||
if err := s.activeMakerOrders.GracefulCancel(ctx, s.session.Exchange); err != nil {
|
if err := s.activeMakerOrders.GracefulCancel(ctx, s.session.Exchange); err != nil {
|
||||||
log.WithError(err).Errorf("graceful cancel order error")
|
log.WithError(err).Errorf("graceful cancel order error")
|
||||||
|
|
|
@ -807,8 +807,7 @@ func (s *Strategy) CrossRun(ctx context.Context, orderExecutionRouter bbgo.Order
|
||||||
defer tradeScanTicker.Stop()
|
defer tradeScanTicker.Stop()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := s.activeMakerOrders.GracefulCancel(context.Background(),
|
if err := s.activeMakerOrders.GracefulCancel(context.Background(), s.makerSession.Exchange); err != nil {
|
||||||
s.makerSession.Exchange); err != nil {
|
|
||||||
log.WithError(err).Errorf("can not cancel %s orders", s.Symbol)
|
log.WithError(err).Errorf("can not cancel %s orders", s.Symbol)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user