Merge pull request #1110 from andycheng123/fix/bollmaker

FIX: [bollmaker] MinProfitActivationRate is disabled if it's not set
This commit is contained in:
Yo-An Lin 2023-03-15 11:18:35 +08:00 committed by GitHub
commit c37bc27217
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,9 +83,9 @@ type Strategy struct {
MinProfitSpread fixedpoint.Value `json:"minProfitSpread"`
// MinProfitActivationRate activates MinProfitSpread when position RoI higher than the specified percentage
MinProfitActivationRate fixedpoint.Value `json:"minProfitActivationRate"`
MinProfitActivationRate *fixedpoint.Value `json:"minProfitActivationRate"`
// UseTickerPrice use the ticker api to get the mid price instead of the closed kline price.
// 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.
UseTickerPrice bool `json:"useTickerPrice"`
@ -336,7 +336,7 @@ func (s *Strategy) placeOrders(ctx context.Context, midPrice fixedpoint.Value, k
// Apply quantity skew
// CASE #1:
// WHEN: price is in the neutral bollginer band (window 1) == neutral
// WHEN: price is in the neutral bollinger band (window 1) == neutral
// THEN: we don't apply skew
// CASE #2:
// WHEN: price is in the upper band (window 2 > price > window 1) == upTrend
@ -385,7 +385,7 @@ func (s *Strategy) placeOrders(ctx context.Context, midPrice fixedpoint.Value, k
isLongPosition := s.Position.IsLong()
isShortPosition := s.Position.IsShort()
if s.Position.ROI(midPrice).Compare(s.MinProfitActivationRate) >= 0 {
if s.MinProfitActivationRate == nil || (s.MinProfitActivationRate != nil && 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))