From d4330a7a3260776d7f4b48ab289d38e88597d0b8 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 27 Sep 2023 14:25:49 +0800 Subject: [PATCH] atrpin: add minPriceRange config --- config/atrpin.yaml | 9 +++++---- pkg/strategy/atrpin/strategy.go | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/config/atrpin.yaml b/config/atrpin.yaml index 759ee60a6..18b6c67b1 100644 --- a/config/atrpin.yaml +++ b/config/atrpin.yaml @@ -1,6 +1,6 @@ sessions: max: - exchange: max + exchange: &exchange max envVarPrefix: max persistence: @@ -12,13 +12,14 @@ persistence: db: 0 exchangeStrategies: -- on: max +- on: *exchange atrpin: symbol: BTCUSDT interval: 5m window: 14 multiplier: 100.0 - amount: 1000 + minPriceRange: 20% + amount: 100 backtest: startTime: "2018-10-01" @@ -26,7 +27,7 @@ backtest: symbols: - BTCUSDT sessions: - - max + - *exchange # syncSecKLines: true accounts: max: diff --git a/pkg/strategy/atrpin/strategy.go b/pkg/strategy/atrpin/strategy.go index dbc5261ce..cd817fa69 100644 --- a/pkg/strategy/atrpin/strategy.go +++ b/pkg/strategy/atrpin/strategy.go @@ -27,9 +27,10 @@ type Strategy struct { Symbol string `json:"symbol"` - Interval types.Interval `json:"interval"` - Window int `json:"window"` - Multiplier float64 `json:"multiplier"` + Interval types.Interval `json:"interval"` + Window int `json:"window"` + Multiplier float64 `json:"multiplier"` + MinPriceRange fixedpoint.Value `json:"minPriceRange"` bbgo.QuantityOrAmount // bbgo.OpenPositionOptions @@ -92,7 +93,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se // if the atr is too small, apply the price range protection with 10% // priceRange protection 10% - priceRange = fixedpoint.Max(priceRange, k.Close.Mul(fixedpoint.NewFromFloat(0.1))) + priceRange = fixedpoint.Max(priceRange, k.Close.Mul(s.MinPriceRange)) log.Infof("priceRange: %f", priceRange.Float64()) ticker, err := session.Exchange.QueryTicker(ctx, s.Symbol)