atrpin: add minPriceRange config

This commit is contained in:
c9s 2023-09-27 14:25:49 +08:00
parent e52e53aa42
commit d4330a7a32
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 10 additions and 8 deletions

View File

@ -1,6 +1,6 @@
sessions: sessions:
max: max:
exchange: max exchange: &exchange max
envVarPrefix: max envVarPrefix: max
persistence: persistence:
@ -12,13 +12,14 @@ persistence:
db: 0 db: 0
exchangeStrategies: exchangeStrategies:
- on: max - on: *exchange
atrpin: atrpin:
symbol: BTCUSDT symbol: BTCUSDT
interval: 5m interval: 5m
window: 14 window: 14
multiplier: 100.0 multiplier: 100.0
amount: 1000 minPriceRange: 20%
amount: 100
backtest: backtest:
startTime: "2018-10-01" startTime: "2018-10-01"
@ -26,7 +27,7 @@ backtest:
symbols: symbols:
- BTCUSDT - BTCUSDT
sessions: sessions:
- max - *exchange
# syncSecKLines: true # syncSecKLines: true
accounts: accounts:
max: max:

View File

@ -27,9 +27,10 @@ type Strategy struct {
Symbol string `json:"symbol"` Symbol string `json:"symbol"`
Interval types.Interval `json:"interval"` Interval types.Interval `json:"interval"`
Window int `json:"window"` Window int `json:"window"`
Multiplier float64 `json:"multiplier"` Multiplier float64 `json:"multiplier"`
MinPriceRange fixedpoint.Value `json:"minPriceRange"`
bbgo.QuantityOrAmount bbgo.QuantityOrAmount
// bbgo.OpenPositionOptions // 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% // if the atr is too small, apply the price range protection with 10%
// priceRange protection 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()) log.Infof("priceRange: %f", priceRange.Float64())
ticker, err := session.Exchange.QueryTicker(ctx, s.Symbol) ticker, err := session.Exchange.QueryTicker(ctx, s.Symbol)