From d973d95121c79ce3499ebe9652838544b11da9fd Mon Sep 17 00:00:00 2001 From: lychiyu Date: Wed, 31 Jul 2024 07:44:52 +0800 Subject: [PATCH] =?UTF-8?q?atr=E8=AE=A1=E7=AE=97=E6=AD=A2=E7=9B=88?= =?UTF-8?q?=E6=AD=A2=E6=8D=9F=E6=98=AF=20=E5=8A=A0=E4=B8=8A=E5=8F=AF?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=9A=84=E6=AF=94=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/ccinr.yaml | 2 ++ pkg/strategy/ccinr/strategy.go | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/config/ccinr.yaml b/config/ccinr.yaml index 272b74f..cc3183e 100644 --- a/config/ccinr.yaml +++ b/config/ccinr.yaml @@ -55,6 +55,8 @@ exchangeStrategies: placePriceType: 2 lossType: 1 profitOrderType: 0 + atrProfitRange: 0.8 + atrLossRange: 1.0 # recalculate: false # dry_run: false # # quantity: 3 diff --git a/pkg/strategy/ccinr/strategy.go b/pkg/strategy/ccinr/strategy.go index cce2bd9..9e31b41 100644 --- a/pkg/strategy/ccinr/strategy.go +++ b/pkg/strategy/ccinr/strategy.go @@ -47,6 +47,8 @@ type Strategy struct { Leverage fixedpoint.Value `json:"leverage"` ProfitRange fixedpoint.Value `json:"profitRange"` LossRange fixedpoint.Value `json:"lossRange"` + AtrProfitRange float64 `json:"atrProfitRange"` + AtrLossRange float64 `json:"atrLossRange"` qbtrade.QuantityOrAmount @@ -221,16 +223,16 @@ func (s *Strategy) generateOrders(ctx context.Context, kline types.KLine) ([]typ lossPrice = placePrice.Sub(placePrice.Mul(s.LossRange)) profitPrice = placePrice.Add(placePrice.Mul(s.ProfitRange)) } else if s.LossType == 1 { - lossPrice = placePrice.Sub(fixedpoint.Value(1e8 * lastATR)) - profitPrice = placePrice.Add(fixedpoint.Value(1e8 * lastATR * 2)) + lossPrice = placePrice.Sub(fixedpoint.Value(1e8 * lastATR * s.AtrLossRange)) + profitPrice = placePrice.Add(fixedpoint.Value(1e8 * lastATR * s.AtrProfitRange)) } } else if s.TradeType[symbol] == "short" { if s.LossType == 0 || s.atr[symbol].Last(0) == 0.0 { lossPrice = placePrice.Add(placePrice.Mul(s.LossRange)) profitPrice = placePrice.Sub(placePrice.Mul(s.ProfitRange)) } else if s.LossType == 1 { - lossPrice = placePrice.Add(fixedpoint.Value(1e8 * lastATR)) - profitPrice = placePrice.Sub(fixedpoint.Value(1e8 * lastATR * 2)) + lossPrice = placePrice.Add(fixedpoint.Value(1e8 * lastATR * s.AtrLossRange)) + profitPrice = placePrice.Sub(fixedpoint.Value(1e8 * lastATR * s.AtrProfitRange)) } }