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:
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:

View File

@ -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)