strategy/supertrend: add ExitMethod

This commit is contained in:
Andy Cheng 2022-07-05 16:55:48 +08:00
parent f0dc9d6147
commit 91077ce61d
2 changed files with 16 additions and 2 deletions

View File

@ -71,3 +71,10 @@ exchangeStrategies:
# TP/SL by reversed linear regression signal # TP/SL by reversed linear regression signal
stopByReversedLinGre: false stopByReversedLinGre: false
exits:
# Protective stop loss
- protectiveStopLoss:
activationRatio: 0.6%
stopLossRatio: 1%
placeStopOrder: false

View File

@ -23,8 +23,7 @@ const stateKey = "state-v1"
var log = logrus.WithField("strategy", ID) var log = logrus.WithField("strategy", ID)
// TODO: SL by fixed percentage // TODO: limit order for ATR TP
// TODO: limit order if possible
func init() { func init() {
// Register the pointer of the strategy struct, // Register the pointer of the strategy struct,
@ -144,6 +143,9 @@ type Strategy struct {
currentTakeProfitPrice fixedpoint.Value currentTakeProfitPrice fixedpoint.Value
currentStopLossPrice fixedpoint.Value currentStopLossPrice fixedpoint.Value
// ExitMethods Exit methods
ExitMethods []bbgo.ExitMethod `json:"exits"`
// StrategyController // StrategyController
bbgo.StrategyController bbgo.StrategyController
} }
@ -363,6 +365,11 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
// Setup indicators // Setup indicators
s.setupIndicators() s.setupIndicators()
// Exit methods
for _, method := range s.ExitMethods {
method.Bind(session, s.orderExecutor)
}
s.currentStopLossPrice = fixedpoint.Zero s.currentStopLossPrice = fixedpoint.Zero
s.currentTakeProfitPrice = fixedpoint.Zero s.currentTakeProfitPrice = fixedpoint.Zero