fix/bollmaker: fix s.MinProfitActivationRate condition

This commit is contained in:
Andy Cheng 2023-03-15 11:06:26 +08:00
parent ca4890425c
commit 0a6c41cfe7
No known key found for this signature in database
GPG Key ID: 936427CF651A9D28

View File

@ -85,7 +85,7 @@ type Strategy struct {
// 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.
// 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.MinProfitActivationRate == nil || 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))