mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
strategy: pivot: add shadow TP
strategy: pivot: add shadow TP
This commit is contained in:
parent
04ae49263d
commit
1a441425b5
|
@ -13,6 +13,7 @@ exchangeStrategies:
|
|||
quantity: 0.95
|
||||
stopLossRatio: 0.8%
|
||||
catBounceRatio: 3%
|
||||
shadowTPRatio: 2.5%
|
||||
|
||||
backtest:
|
||||
sessions:
|
||||
|
@ -28,4 +29,4 @@ backtest:
|
|||
binance:
|
||||
balances:
|
||||
BTC: 1.0
|
||||
BUSD: 5_000.0
|
||||
BUSD: 1_000.0
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
const ID = "pivot"
|
||||
|
||||
var fifteen = fixedpoint.NewFromInt(15)
|
||||
var three = fixedpoint.NewFromInt(3)
|
||||
|
||||
var log = logrus.WithField("strategy", ID)
|
||||
|
@ -32,13 +33,13 @@ type Strategy struct {
|
|||
Position *types.Position `json:"position,omitempty"`
|
||||
StopLossRatio fixedpoint.Value `json:"stopLossRatio"`
|
||||
CatBounceRatio fixedpoint.Value `json:"catBounceRatio"`
|
||||
ShadowTPRatio fixedpoint.Value `json:"shadowTPRatio"`
|
||||
|
||||
activeMakerOrders *bbgo.LocalActiveOrderBook
|
||||
orderStore *bbgo.OrderStore
|
||||
tradeCollector *bbgo.TradeCollector
|
||||
|
||||
session *bbgo.ExchangeSession
|
||||
book *types.StreamOrderBook
|
||||
|
||||
//pivotHigh *PIVOTHIGH
|
||||
pivot *Pivot
|
||||
|
@ -139,11 +140,16 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
} else {
|
||||
lastLow = fixedpoint.Zero
|
||||
// SL || TP
|
||||
if kline.Close.Div(s.Position.AverageCost).Compare(fixedpoint.One.Add(s.StopLossRatio)) > 0 || kline.Close.Div(s.Position.AverageCost).Compare(fixedpoint.One.Sub(s.StopLossRatio.Mul(fixedpoint.NewFromInt(15)))) < 0 {
|
||||
R := kline.Close.Div(s.Position.AverageCost)
|
||||
if R.Compare(fixedpoint.One.Add(s.StopLossRatio)) > 0 || R.Compare(fixedpoint.One.Sub(s.StopLossRatio.Mul(fifteen))) < 0 {
|
||||
if s.Position.GetBase().Compare(s.Quantity.Neg()) <= 0 {
|
||||
s.ClosePosition(ctx, fixedpoint.One)
|
||||
s.tradeCollector.Process()
|
||||
}
|
||||
// shadow TP
|
||||
} else if kline.GetLowerShadowHeight().Div(kline.Close).Compare(s.ShadowTPRatio) > 0 {
|
||||
s.ClosePosition(ctx, fixedpoint.One)
|
||||
s.tradeCollector.Process()
|
||||
}
|
||||
}
|
||||
if !lastLow.IsZero() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user