Merge pull request #810 from andycheng123/fix/supertrend-strategy

This commit is contained in:
Yo-An Lin 2022-07-08 21:03:01 +08:00 committed by GitHub
commit eacbd13e6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 19 deletions

View File

@ -38,6 +38,11 @@ exchangeStrategies:
# interval is how long do you want to update your order price and quantity
interval: 5m
# ATR window used by Supertrend
window: 49
# ATR Multiplier for calculating super trend prices, the higher, the stronger the trends are
supertrendMultiplier: 4
# leverage is the leverage of the orders
leverage: 1.0
@ -45,13 +50,6 @@ exchangeStrategies:
fastDEMAWindow: 144
slowDEMAWindow: 169
# Supertrend indicator parameters
superTrend:
# ATR window used by Supertrend
averageTrueRangeWindow: 49
# ATR Multiplier for calculating super trend prices, the higher, the stronger the trends are
averageTrueRangeMultiplier: 4
# Use linear regression as trend confirmation
linearRegression:
interval: 5m
@ -76,3 +74,7 @@ exchangeStrategies:
# roiStopLoss is the stop loss percentage of the position ROI (currently the price change)
- roiStopLoss:
percentage: 4%
- protectiveStopLoss:
activationRatio: 3%
stopLossRatio: 2%
placeStopOrder: false

View File

@ -7,7 +7,7 @@ import (
)
type DoubleDema struct {
Interval types.Interval `json:"interval"`
DemaInterval types.Interval `json:"demaInterval"`
// FastDEMAWindow DEMA window for checking breakout
FastDEMAWindow int `json:"fastDEMAWindow"`
@ -46,19 +46,19 @@ func (dd *DoubleDema) preloadDema(kLineStore *bbgo.MarketDataStore) {
// setupDoubleDema initializes double DEMA indicators
func (dd *DoubleDema) setupDoubleDema(kLineStore *bbgo.MarketDataStore, interval types.Interval) {
dd.Interval = interval
dd.DemaInterval = interval
// DEMA
if dd.FastDEMAWindow == 0 {
dd.FastDEMAWindow = 144
}
dd.fastDEMA = &indicator.DEMA{IntervalWindow: types.IntervalWindow{Interval: dd.Interval, Window: dd.FastDEMAWindow}}
dd.fastDEMA = &indicator.DEMA{IntervalWindow: types.IntervalWindow{Interval: dd.DemaInterval, Window: dd.FastDEMAWindow}}
dd.fastDEMA.Bind(kLineStore)
if dd.SlowDEMAWindow == 0 {
dd.SlowDEMAWindow = 169
}
dd.slowDEMA = &indicator.DEMA{IntervalWindow: types.IntervalWindow{Interval: dd.Interval, Window: dd.SlowDEMAWindow}}
dd.slowDEMA = &indicator.DEMA{IntervalWindow: types.IntervalWindow{Interval: dd.DemaInterval, Window: dd.SlowDEMAWindow}}
dd.slowDEMA.Bind(kLineStore)
dd.preloadDema(kLineStore)

View File

@ -44,12 +44,8 @@ type Strategy struct {
// Double DEMA
DoubleDema *DoubleDema
// SuperTrend indicator
// SuperTrend SuperTrend `json:"superTrend"`
Supertrend *indicator.Supertrend
// SupertrendWindow ATR window for calculation of supertrend
SupertrendWindow int `json:"supertrendWindow"`
// SupertrendMultiplier ATR multiplier for calculation of supertrend
SupertrendMultiplier float64 `json:"supertrendMultiplier"`
@ -112,6 +108,7 @@ func (s *Strategy) Validate() error {
func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval})
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.LinearRegression.Interval})
}
// Position control
@ -168,14 +165,14 @@ func (s *Strategy) setupIndicators() {
s.DoubleDema.setupDoubleDema(kLineStore, s.Interval)
// Supertrend
if s.SupertrendWindow == 0 {
s.SupertrendWindow = 39
if s.Window == 0 {
s.Window = 39
}
if s.SupertrendMultiplier == 0 {
s.SupertrendMultiplier = 3
}
s.Supertrend = &indicator.Supertrend{IntervalWindow: types.IntervalWindow{Window: s.SupertrendWindow, Interval: s.Interval}, ATRMultiplier: s.SupertrendMultiplier}
s.Supertrend.AverageTrueRange = &indicator.ATR{IntervalWindow: types.IntervalWindow{Window: s.SupertrendWindow, Interval: s.Interval}}
s.Supertrend = &indicator.Supertrend{IntervalWindow: types.IntervalWindow{Window: s.Window, Interval: s.Interval}, ATRMultiplier: s.SupertrendMultiplier}
s.Supertrend.AverageTrueRange = &indicator.ATR{IntervalWindow: types.IntervalWindow{Window: s.Window, Interval: s.Interval}}
s.Supertrend.Bind(kLineStore)
preloadSupertrend(s.Supertrend, kLineStore)