From e3be2a8af63a27168828dadb28159149ab65d139 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 29 Jun 2023 18:04:39 +0800 Subject: [PATCH] bollmaker: replace bollinger indicator with v2 indicator --- pkg/strategy/bollmaker/dynamic_spread.go | 10 +++++----- pkg/strategy/bollmaker/strategy.go | 8 ++++---- pkg/strategy/bollmaker/trend.go | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/strategy/bollmaker/dynamic_spread.go b/pkg/strategy/bollmaker/dynamic_spread.go index 51785f3df..b6ede2156 100644 --- a/pkg/strategy/bollmaker/dynamic_spread.go +++ b/pkg/strategy/bollmaker/dynamic_spread.go @@ -1,9 +1,10 @@ package bollmaker import ( - "github.com/pkg/errors" "math" + "github.com/pkg/errors" + "github.com/c9s/bbgo/pkg/bbgo" "github.com/c9s/bbgo/pkg/indicator" "github.com/c9s/bbgo/pkg/types" @@ -27,7 +28,7 @@ type DynamicSpreadSettings struct { } // Initialize dynamic spreads and preload SMAs -func (ds *DynamicSpreadSettings) Initialize(symbol string, session *bbgo.ExchangeSession, neutralBoll, defaultBoll *indicator.BOLL) { +func (ds *DynamicSpreadSettings) Initialize(symbol string, session *bbgo.ExchangeSession, neutralBoll, defaultBoll *indicator.BOLLStream) { switch { case ds.AmpSpreadSettings != nil: ds.AmpSpreadSettings.initialize(symbol, session) @@ -163,11 +164,10 @@ type DynamicSpreadBollWidthRatioSettings struct { // A positive number. The greater factor, the sharper weighting function. Default set to 1.0 . Sensitivity float64 `json:"sensitivity"` - neutralBoll *indicator.BOLL - defaultBoll *indicator.BOLL + defaultBoll, neutralBoll *indicator.BOLLStream } -func (ds *DynamicSpreadBollWidthRatioSettings) initialize(neutralBoll, defaultBoll *indicator.BOLL) { +func (ds *DynamicSpreadBollWidthRatioSettings) initialize(neutralBoll, defaultBoll *indicator.BOLLStream) { ds.neutralBoll = neutralBoll ds.defaultBoll = defaultBoll if ds.Sensitivity <= 0. { diff --git a/pkg/strategy/bollmaker/strategy.go b/pkg/strategy/bollmaker/strategy.go index efd1742d2..a2233b44d 100644 --- a/pkg/strategy/bollmaker/strategy.go +++ b/pkg/strategy/bollmaker/strategy.go @@ -158,10 +158,10 @@ type Strategy struct { groupID uint32 // defaultBoll is the BOLLINGER indicator we used for predicting the price. - defaultBoll *indicator.BOLL + defaultBoll *indicator.BOLLStream // neutralBoll is the neutral price section - neutralBoll *indicator.BOLL + neutralBoll *indicator.BOLLStream // StrategyController bbgo.StrategyController @@ -465,8 +465,8 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se // StrategyController s.Status = types.StrategyStatusRunning - s.neutralBoll = s.StandardIndicatorSet.BOLL(s.NeutralBollinger.IntervalWindow, s.NeutralBollinger.BandWidth) - s.defaultBoll = s.StandardIndicatorSet.BOLL(s.DefaultBollinger.IntervalWindow, s.DefaultBollinger.BandWidth) + s.neutralBoll = session.Indicators(s.Symbol).BOLL(s.NeutralBollinger.IntervalWindow, s.NeutralBollinger.BandWidth) + s.defaultBoll = session.Indicators(s.Symbol).BOLL(s.DefaultBollinger.IntervalWindow, s.DefaultBollinger.BandWidth) // Setup dynamic spread if s.DynamicSpread.IsEnabled() { diff --git a/pkg/strategy/bollmaker/trend.go b/pkg/strategy/bollmaker/trend.go index 4c0cb7fcd..7e4ddcf71 100644 --- a/pkg/strategy/bollmaker/trend.go +++ b/pkg/strategy/bollmaker/trend.go @@ -11,16 +11,16 @@ const ( UnknownTrend PriceTrend = "unknown" ) -func detectPriceTrend(inc *indicator.BOLL, price float64) PriceTrend { +func detectPriceTrend(inc *indicator.BOLLStream, price float64) PriceTrend { if inBetween(price, inc.DownBand.Last(0), inc.UpBand.Last(0)) { return NeutralTrend } - if price < inc.LastDownBand() { + if price < inc.DownBand.Last(0) { return DownTrend } - if price > inc.LastUpBand() { + if price > inc.UpBand.Last(0) { return UpTrend }