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