From 65218d8920476432ff651bb926d65a52606d2ff3 Mon Sep 17 00:00:00 2001 From: ankion Date: Fri, 12 Aug 2022 00:54:40 +0800 Subject: [PATCH] pivotshort: trendema add length check --- pkg/strategy/pivotshort/trendema.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/strategy/pivotshort/trendema.go b/pkg/strategy/pivotshort/trendema.go index 98c8c29ce..a02572a98 100644 --- a/pkg/strategy/pivotshort/trendema.go +++ b/pkg/strategy/pivotshort/trendema.go @@ -22,8 +22,10 @@ func (s *TrendEMA) Bind(session *bbgo.ExchangeSession, orderExecutor *bbgo.Gener symbol := orderExecutor.Position().Symbol s.trendEWMA = session.StandardIndicatorSet(symbol).EWMA(s.IntervalWindow) session.MarketDataStream.OnStart(func() { - s.trendEWMALast = s.trendEWMA.Values[s.trendEWMA.Length()-2] - s.trendEWMACurrent = s.trendEWMA.Last() + if s.trendEWMA.Length() > 1 { + s.trendEWMALast = s.trendEWMA.Values[s.trendEWMA.Length()-2] + s.trendEWMACurrent = s.trendEWMA.Last() + } }) session.MarketDataStream.OnKLineClosed(types.KLineWith(symbol, s.Interval, func(kline types.KLine) { s.trendEWMALast = s.trendEWMACurrent