strategy: supertrend strategy config example

This commit is contained in:
Andy Cheng 2022-05-30 16:48:07 +08:00
parent 756284378b
commit d72a4e8e94
2 changed files with 62 additions and 0 deletions

48
config/supertrend.yaml Normal file
View File

@ -0,0 +1,48 @@
---
persistence:
redis:
host: 127.0.0.1
port: 6379
db: 0
sessions:
binance:
exchange: binance
envVarPrefix: binance
backtest:
sessions: [binance]
# for testing max draw down (MDD) at 03-12
# see here for more details
# https://www.investopedia.com/terms/m/maximum-drawdown-mdd.asp
startTime: "2022-04-01"
endTime: "2022-04-30"
symbols:
- BTCUSDT
accounts:
binance:
makerCommission: 10 # 0.15%
takerCommission: 15 # 0.15%
balances:
BTC: 1.0
USDT: 10000.0
exchangeStrategies:
- on: binance
supertrend:
symbol: BTCUSDT
# interval is how long do you want to update your order price and quantity
interval: 1h
# leverage is the leverage of the orders
leverage: 1
# fastDEMAWindow and slowDEMAWindow are for filtering super trend noise
fastDEMAWindow: 144
slowDEMAWindow: 169
superTrend:
averageTrueRangeWindow: 39
# ATR Multiplier for calculating super trend prices, the higher, the stronger the trends are
averageTrueRangeMultiplier: 3

View File

@ -10,6 +10,7 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"math"
"sync"
)
// TODO: Strategy control
@ -121,6 +122,8 @@ type Strategy struct {
// groupID is the group ID used for the strategy instance for canceling orders
groupID uint32
stopC chan struct{}
// Symbol is the market symbol you want to trade
Symbol string `json:"symbol"`
@ -284,6 +287,9 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
s.Position.Strategy = ID
s.Position.StrategyInstanceID = s.InstanceID()
s.stopC = make(chan struct{})
// Profit
if s.ProfitStats == nil {
s.ProfitStats = types.NewProfitStats(s.Market)
}
@ -402,5 +408,13 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
s.tradeCollector.BindStream(session.UserDataStream)
// Graceful shutdown
s.Graceful.OnShutdown(func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
close(s.stopC)
s.tradeCollector.Process()
})
return nil
}