mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
improve/bollmaker: add MinProfitActivationRate
This commit is contained in:
parent
5fc459d404
commit
cb412dc13f
|
@ -59,6 +59,9 @@ exchangeStrategies:
|
|||
# For short position, you will only place buy order below the price (= average cost * (1 - minProfitSpread))
|
||||
minProfitSpread: 0.1%
|
||||
|
||||
# minProfitActivationRate activates MinProfitSpread when position RoI higher than the specified percentage
|
||||
minProfitActivationRate: -10%
|
||||
|
||||
# trendEMA detects the trend by a given EMA
|
||||
# when EMA goes up (the last > the previous), allow buy and sell
|
||||
# when EMA goes down (the last < the previous), disable buy, allow sell
|
||||
|
|
|
@ -82,6 +82,9 @@ type Strategy struct {
|
|||
// For short position, you will only place buy order below the price (= average cost * (1 - minProfitSpread))
|
||||
MinProfitSpread fixedpoint.Value `json:"minProfitSpread"`
|
||||
|
||||
// MinProfitActivationRate activates MinProfitSpread when position RoI higher than the specified percentage
|
||||
MinProfitActivationRate fixedpoint.Value `json:"minProfitActivationRate"`
|
||||
|
||||
// UseTickerPrice use the ticker api to get the mid price instead of the closed kline price.
|
||||
// The back-test engine is kline-based, so the ticker price api is not supported.
|
||||
// Turn this on if you want to do real trading.
|
||||
|
@ -381,22 +384,25 @@ func (s *Strategy) placeOrders(ctx context.Context, midPrice fixedpoint.Value, k
|
|||
|
||||
isLongPosition := s.Position.IsLong()
|
||||
isShortPosition := s.Position.IsShort()
|
||||
minProfitPrice := s.Position.AverageCost.Mul(fixedpoint.One.Add(s.MinProfitSpread))
|
||||
if isShortPosition {
|
||||
minProfitPrice = s.Position.AverageCost.Mul(fixedpoint.One.Sub(s.MinProfitSpread))
|
||||
}
|
||||
|
||||
if isLongPosition {
|
||||
// for long position if the current price is lower than the minimal profitable price then we should stop sell
|
||||
// this avoid loss trade
|
||||
if midPrice.Compare(minProfitPrice) < 0 {
|
||||
canSell = false
|
||||
if s.Position.ROI(midPrice).Compare(s.MinProfitActivationRate) >= 0 {
|
||||
minProfitPrice := s.Position.AverageCost.Mul(fixedpoint.One.Add(s.MinProfitSpread))
|
||||
if isShortPosition {
|
||||
minProfitPrice = s.Position.AverageCost.Mul(fixedpoint.One.Sub(s.MinProfitSpread))
|
||||
}
|
||||
} else if isShortPosition {
|
||||
// for short position if the current price is higher than the minimal profitable price then we should stop buy
|
||||
// this avoid loss trade
|
||||
if midPrice.Compare(minProfitPrice) > 0 {
|
||||
canBuy = false
|
||||
|
||||
if isLongPosition {
|
||||
// for long position if the current price is lower than the minimal profitable price then we should stop sell
|
||||
// this avoids loss trade
|
||||
if midPrice.Compare(minProfitPrice) < 0 {
|
||||
canSell = false
|
||||
}
|
||||
} else if isShortPosition {
|
||||
// for short position if the current price is higher than the minimal profitable price then we should stop buy
|
||||
// this avoids loss trade
|
||||
if midPrice.Compare(minProfitPrice) > 0 {
|
||||
canBuy = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user