mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
strategy/supertrend: use types.IntervalWindow instead of types.Interval
This commit is contained in:
parent
46d6ecc663
commit
574e142cf9
|
@ -38,6 +38,11 @@ exchangeStrategies:
|
||||||
# interval is how long do you want to update your order price and quantity
|
# interval is how long do you want to update your order price and quantity
|
||||||
interval: 5m
|
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 is the leverage of the orders
|
||||||
leverage: 1.0
|
leverage: 1.0
|
||||||
|
|
||||||
|
@ -45,13 +50,6 @@ exchangeStrategies:
|
||||||
fastDEMAWindow: 144
|
fastDEMAWindow: 144
|
||||||
slowDEMAWindow: 169
|
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
|
# Use linear regression as trend confirmation
|
||||||
linearRegression:
|
linearRegression:
|
||||||
interval: 5m
|
interval: 5m
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type DoubleDema struct {
|
type DoubleDema struct {
|
||||||
Interval types.Interval `json:"interval"`
|
DemaInterval types.Interval `json:"demaInterval"`
|
||||||
|
|
||||||
// FastDEMAWindow DEMA window for checking breakout
|
// FastDEMAWindow DEMA window for checking breakout
|
||||||
FastDEMAWindow int `json:"fastDEMAWindow"`
|
FastDEMAWindow int `json:"fastDEMAWindow"`
|
||||||
|
@ -46,19 +46,19 @@ func (dd *DoubleDema) preloadDema(kLineStore *bbgo.MarketDataStore) {
|
||||||
|
|
||||||
// setupDoubleDema initializes double DEMA indicators
|
// setupDoubleDema initializes double DEMA indicators
|
||||||
func (dd *DoubleDema) setupDoubleDema(kLineStore *bbgo.MarketDataStore, interval types.Interval) {
|
func (dd *DoubleDema) setupDoubleDema(kLineStore *bbgo.MarketDataStore, interval types.Interval) {
|
||||||
dd.Interval = interval
|
dd.DemaInterval = interval
|
||||||
|
|
||||||
// DEMA
|
// DEMA
|
||||||
if dd.FastDEMAWindow == 0 {
|
if dd.FastDEMAWindow == 0 {
|
||||||
dd.FastDEMAWindow = 144
|
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)
|
dd.fastDEMA.Bind(kLineStore)
|
||||||
|
|
||||||
if dd.SlowDEMAWindow == 0 {
|
if dd.SlowDEMAWindow == 0 {
|
||||||
dd.SlowDEMAWindow = 169
|
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.slowDEMA.Bind(kLineStore)
|
||||||
|
|
||||||
dd.preloadDema(kLineStore)
|
dd.preloadDema(kLineStore)
|
||||||
|
|
|
@ -39,17 +39,13 @@ type Strategy struct {
|
||||||
// Symbol is the market symbol you want to trade
|
// Symbol is the market symbol you want to trade
|
||||||
Symbol string `json:"symbol"`
|
Symbol string `json:"symbol"`
|
||||||
|
|
||||||
|
types.IntervalWindow
|
||||||
|
|
||||||
// Double DEMA
|
// Double DEMA
|
||||||
DoubleDema
|
DoubleDema
|
||||||
|
|
||||||
// Interval is how long do you want to update your order price and quantity
|
|
||||||
Interval types.Interval `json:"interval"`
|
|
||||||
|
|
||||||
// SuperTrend indicator
|
// SuperTrend indicator
|
||||||
// SuperTrend SuperTrend `json:"superTrend"`
|
|
||||||
Supertrend *indicator.Supertrend
|
Supertrend *indicator.Supertrend
|
||||||
// SupertrendWindow ATR window for calculation of supertrend
|
|
||||||
SupertrendWindow int `json:"supertrendWindow"`
|
|
||||||
// SupertrendMultiplier ATR multiplier for calculation of supertrend
|
// SupertrendMultiplier ATR multiplier for calculation of supertrend
|
||||||
SupertrendMultiplier float64 `json:"supertrendMultiplier"`
|
SupertrendMultiplier float64 `json:"supertrendMultiplier"`
|
||||||
|
|
||||||
|
@ -112,6 +108,7 @@ func (s *Strategy) Validate() error {
|
||||||
|
|
||||||
func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
|
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.Interval})
|
||||||
|
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.LinearRegression.Interval})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Position control
|
// Position control
|
||||||
|
@ -168,14 +165,14 @@ func (s *Strategy) setupIndicators() {
|
||||||
s.setupDoubleDema(kLineStore, s.Interval)
|
s.setupDoubleDema(kLineStore, s.Interval)
|
||||||
|
|
||||||
// Supertrend
|
// Supertrend
|
||||||
if s.SupertrendWindow == 0 {
|
if s.Window == 0 {
|
||||||
s.SupertrendWindow = 39
|
s.Window = 39
|
||||||
}
|
}
|
||||||
if s.SupertrendMultiplier == 0 {
|
if s.SupertrendMultiplier == 0 {
|
||||||
s.SupertrendMultiplier = 3
|
s.SupertrendMultiplier = 3
|
||||||
}
|
}
|
||||||
s.Supertrend = &indicator.Supertrend{IntervalWindow: types.IntervalWindow{Window: s.SupertrendWindow, Interval: s.Interval}, ATRMultiplier: s.SupertrendMultiplier}
|
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.SupertrendWindow, Interval: s.Interval}}
|
s.Supertrend.AverageTrueRange = &indicator.ATR{IntervalWindow: types.IntervalWindow{Window: s.Window, Interval: s.Interval}}
|
||||||
s.Supertrend.Bind(kLineStore)
|
s.Supertrend.Bind(kLineStore)
|
||||||
preloadSupertrend(s.Supertrend, kLineStore)
|
preloadSupertrend(s.Supertrend, kLineStore)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user