mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
pivotshort: fix bounce short
This commit is contained in:
parent
ec68dc2f40
commit
3d0c0717ba
|
@ -54,18 +54,18 @@ exchangeStrategies:
|
||||||
# ratio is the ratio of the resistance price,
|
# ratio is the ratio of the resistance price,
|
||||||
# higher the ratio, lower the price
|
# higher the ratio, lower the price
|
||||||
# first_layer_price = resistance_price * (1 - ratio)
|
# first_layer_price = resistance_price * (1 - ratio)
|
||||||
# second_layer_price = (resistance_price * (1 - ratio)) * (1.0 + layerSpread)
|
# second_layer_price = (resistance_price * (1 - ratio)) * (2 * layerSpread)
|
||||||
ratio: 0.1%
|
ratio: 0%
|
||||||
numOfLayers: 10
|
numOfLayers: 1
|
||||||
layerSpread: 0.1%
|
layerSpread: 0.1%
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
# roiStopLossPercentage is the stop loss percentage of the position ROI (currently the price change)
|
# roiStopLossPercentage is the stop loss percentage of the position ROI (currently the price change)
|
||||||
roiStopLossPercentage: 1%
|
roiStopLossPercentage: 2%
|
||||||
|
|
||||||
# roiTakeProfitPercentage is used to force taking profit by percentage of the position ROI (currently the price change)
|
# roiTakeProfitPercentage is used to force taking profit by percentage of the position ROI (currently the price change)
|
||||||
# force to take the profit ROI exceeded the percentage.
|
# force to take the profit ROI exceeded the percentage.
|
||||||
roiTakeProfitPercentage: 25%
|
roiTakeProfitPercentage: 30%
|
||||||
|
|
||||||
# roiMinTakeProfitPercentage applies to lowerShadowRatio and cumulatedVolume exit options
|
# roiMinTakeProfitPercentage applies to lowerShadowRatio and cumulatedVolume exit options
|
||||||
roiMinTakeProfitPercentage: 10%
|
roiMinTakeProfitPercentage: 10%
|
||||||
|
|
|
@ -335,8 +335,16 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
log.Infof("last price: %f, possible resistance prices: %+v", closePrice, s.resistancePrices)
|
log.Infof("last price: %f, possible resistance prices: %+v", closePrice, s.resistancePrices)
|
||||||
|
|
||||||
if len(s.resistancePrices) > 0 {
|
if len(s.resistancePrices) > 0 {
|
||||||
s.currentBounceShortPrice = fixedpoint.NewFromFloat(s.resistancePrices[0])
|
resistancePrice := fixedpoint.NewFromFloat(s.resistancePrices[0])
|
||||||
s.placeBounceSellOrders(ctx, s.currentBounceShortPrice, orderExecutor)
|
if resistancePrice.Compare(s.currentBounceShortPrice) != 0 {
|
||||||
|
log.Infof("updating resistance price... possible resistance prices: %+v", s.resistancePrices)
|
||||||
|
|
||||||
|
if err := s.activeMakerOrders.GracefulCancel(ctx, s.session.Exchange); err != nil {
|
||||||
|
log.WithError(err).Errorf("graceful cancel order error")
|
||||||
|
}
|
||||||
|
s.currentBounceShortPrice = resistancePrice
|
||||||
|
s.placeBounceSellOrders(ctx, s.currentBounceShortPrice, orderExecutor)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -508,23 +516,26 @@ func (s *Strategy) placeBounceSellOrders(ctx context.Context, resistancePrice fi
|
||||||
if numLayers == 0 {
|
if numLayers == 0 {
|
||||||
numLayers = 1
|
numLayers = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
numLayersF := fixedpoint.NewFromInt(int64(numLayers))
|
numLayersF := fixedpoint.NewFromInt(int64(numLayers))
|
||||||
|
|
||||||
layerSpread := s.BounceShort.LayerSpread
|
layerSpread := s.BounceShort.LayerSpread
|
||||||
if layerSpread.IsZero() {
|
|
||||||
layerSpread = s.BounceShort.Ratio.Div(numLayersF)
|
|
||||||
}
|
|
||||||
|
|
||||||
quantity := totalQuantity.Div(numLayersF)
|
quantity := totalQuantity.Div(numLayersF)
|
||||||
|
|
||||||
|
log.Infof("placing bounce short orders: resistance price = %f, layer quantity = %f, num of layers = %d", resistancePrice.Float64(), quantity.Float64(), numLayers)
|
||||||
|
|
||||||
for i := 0; i < numLayers; i++ {
|
for i := 0; i < numLayers; i++ {
|
||||||
balances := s.session.GetAccount().Balances()
|
balances := s.session.GetAccount().Balances()
|
||||||
quoteBalance, _ := balances[s.Market.QuoteCurrency]
|
quoteBalance, _ := balances[s.Market.QuoteCurrency]
|
||||||
baseBalance, _ := balances[s.Market.BaseCurrency]
|
baseBalance, _ := balances[s.Market.BaseCurrency]
|
||||||
|
|
||||||
// price = (resistance_price * (1.0 - ratio)) * ((1.0 + layerSpread) * i)
|
// price = (resistance_price * (1.0 - ratio)) * ((1.0 + layerSpread) * i)
|
||||||
price := resistancePrice.Mul(
|
price := resistancePrice.Mul(fixedpoint.One.Sub(s.BounceShort.Ratio))
|
||||||
fixedpoint.One.Sub(s.BounceShort.Ratio)).Mul(
|
spread := layerSpread.Mul(fixedpoint.NewFromInt(int64(i)))
|
||||||
fixedpoint.One.Add(layerSpread).Mul(fixedpoint.NewFromInt(int64(i))))
|
price = price.Add(spread)
|
||||||
|
log.Infof("price = %f", price.Float64())
|
||||||
|
|
||||||
|
log.Infof("placing bounce short order #%d: price = %f, quantity = %f", i, price.Float64(), quantity.Float64())
|
||||||
|
|
||||||
if futuresMode {
|
if futuresMode {
|
||||||
if quantity.Mul(price).Compare(quoteBalance.Available) <= 0 {
|
if quantity.Mul(price).Compare(quoteBalance.Available) <= 0 {
|
||||||
|
@ -571,7 +582,6 @@ func (s *Strategy) preloadPivot(pivot *indicator.Pivot, store *bbgo.MarketDataSt
|
||||||
func findPossibleResistancePrices(closePrice float64, minDistance float64, lows []float64) []float64 {
|
func findPossibleResistancePrices(closePrice float64, minDistance float64, lows []float64) []float64 {
|
||||||
// sort float64 in increasing order
|
// sort float64 in increasing order
|
||||||
sort.Float64s(lows)
|
sort.Float64s(lows)
|
||||||
log.Infof("sorted resistance lows: %+v", lows)
|
|
||||||
|
|
||||||
var resistancePrices []float64
|
var resistancePrices []float64
|
||||||
for _, low := range lows {
|
for _, low := range lows {
|
||||||
|
@ -590,6 +600,5 @@ func findPossibleResistancePrices(closePrice float64, minDistance float64, lows
|
||||||
resistancePrices = append(resistancePrices, low)
|
resistancePrices = append(resistancePrices, low)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("possible resistance prices: %+v", resistancePrices)
|
|
||||||
return resistancePrices
|
return resistancePrices
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user