atr计算止盈止损是 加上可配置的比例
This commit is contained in:
parent
29bd6ff6eb
commit
d973d95121
|
@ -55,6 +55,8 @@ exchangeStrategies:
|
||||||
placePriceType: 2
|
placePriceType: 2
|
||||||
lossType: 1
|
lossType: 1
|
||||||
profitOrderType: 0
|
profitOrderType: 0
|
||||||
|
atrProfitRange: 0.8
|
||||||
|
atrLossRange: 1.0
|
||||||
# recalculate: false
|
# recalculate: false
|
||||||
# dry_run: false
|
# dry_run: false
|
||||||
# # quantity: 3
|
# # quantity: 3
|
||||||
|
|
|
@ -47,6 +47,8 @@ type Strategy struct {
|
||||||
Leverage fixedpoint.Value `json:"leverage"`
|
Leverage fixedpoint.Value `json:"leverage"`
|
||||||
ProfitRange fixedpoint.Value `json:"profitRange"`
|
ProfitRange fixedpoint.Value `json:"profitRange"`
|
||||||
LossRange fixedpoint.Value `json:"lossRange"`
|
LossRange fixedpoint.Value `json:"lossRange"`
|
||||||
|
AtrProfitRange float64 `json:"atrProfitRange"`
|
||||||
|
AtrLossRange float64 `json:"atrLossRange"`
|
||||||
|
|
||||||
qbtrade.QuantityOrAmount
|
qbtrade.QuantityOrAmount
|
||||||
|
|
||||||
|
@ -221,16 +223,16 @@ func (s *Strategy) generateOrders(ctx context.Context, kline types.KLine) ([]typ
|
||||||
lossPrice = placePrice.Sub(placePrice.Mul(s.LossRange))
|
lossPrice = placePrice.Sub(placePrice.Mul(s.LossRange))
|
||||||
profitPrice = placePrice.Add(placePrice.Mul(s.ProfitRange))
|
profitPrice = placePrice.Add(placePrice.Mul(s.ProfitRange))
|
||||||
} else if s.LossType == 1 {
|
} else if s.LossType == 1 {
|
||||||
lossPrice = placePrice.Sub(fixedpoint.Value(1e8 * lastATR))
|
lossPrice = placePrice.Sub(fixedpoint.Value(1e8 * lastATR * s.AtrLossRange))
|
||||||
profitPrice = placePrice.Add(fixedpoint.Value(1e8 * lastATR * 2))
|
profitPrice = placePrice.Add(fixedpoint.Value(1e8 * lastATR * s.AtrProfitRange))
|
||||||
}
|
}
|
||||||
} else if s.TradeType[symbol] == "short" {
|
} else if s.TradeType[symbol] == "short" {
|
||||||
if s.LossType == 0 || s.atr[symbol].Last(0) == 0.0 {
|
if s.LossType == 0 || s.atr[symbol].Last(0) == 0.0 {
|
||||||
lossPrice = placePrice.Add(placePrice.Mul(s.LossRange))
|
lossPrice = placePrice.Add(placePrice.Mul(s.LossRange))
|
||||||
profitPrice = placePrice.Sub(placePrice.Mul(s.ProfitRange))
|
profitPrice = placePrice.Sub(placePrice.Mul(s.ProfitRange))
|
||||||
} else if s.LossType == 1 {
|
} else if s.LossType == 1 {
|
||||||
lossPrice = placePrice.Add(fixedpoint.Value(1e8 * lastATR))
|
lossPrice = placePrice.Add(fixedpoint.Value(1e8 * lastATR * s.AtrLossRange))
|
||||||
profitPrice = placePrice.Sub(fixedpoint.Value(1e8 * lastATR * 2))
|
profitPrice = placePrice.Sub(fixedpoint.Value(1e8 * lastATR * s.AtrProfitRange))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user