diff --git a/pkg/bbgo/marketdatastore.go b/pkg/bbgo/marketdatastore.go index 521caa61a..bdc8f60e0 100644 --- a/pkg/bbgo/marketdatastore.go +++ b/pkg/bbgo/marketdatastore.go @@ -3,7 +3,7 @@ package bbgo import "github.com/c9s/bbgo/pkg/types" const MaxNumOfKLines = 5_000 -const MaxNumOfKLinesTruncate = 1_000 +const MaxNumOfKLinesTruncate = 100 // MarketDataStore receives and maintain the public market data //go:generate callbackgen -type MarketDataStore @@ -56,7 +56,7 @@ func (store *MarketDataStore) AddKLine(kline types.KLine) { } if len(window) > MaxNumOfKLines { - window = window[MaxNumOfKLinesTruncate:] + window = window[MaxNumOfKLinesTruncate-1:] } store.KLineWindows[kline.Interval] = window diff --git a/pkg/indicator/ewma.go b/pkg/indicator/ewma.go index e6ea44536..ada48cdb3 100644 --- a/pkg/indicator/ewma.go +++ b/pkg/indicator/ewma.go @@ -11,7 +11,7 @@ import ( // These numbers should be aligned with bbgo MaxNumOfKLines and MaxNumOfKLinesTruncate const MaxNumOfEWMA = 5_000 -const MaxNumOfEWMATruncateSize = 1000 +const MaxNumOfEWMATruncateSize = 100 //go:generate callbackgen -type EWMA type EWMA struct { @@ -29,7 +29,7 @@ func (inc *EWMA) Update(value float64) { inc.Values.Push(value) return } else if len(inc.Values) > MaxNumOfEWMA { - inc.Values = inc.Values[MaxNumOfEWMATruncateSize:] + inc.Values = inc.Values[MaxNumOfEWMATruncateSize - 1:] } ema := (1-multiplier)*inc.Last() + multiplier*value diff --git a/pkg/indicator/sma.go b/pkg/indicator/sma.go index ee87cb17c..fcd0e8ebf 100644 --- a/pkg/indicator/sma.go +++ b/pkg/indicator/sma.go @@ -9,8 +9,8 @@ import ( "github.com/c9s/bbgo/pkg/types" ) -const MaxNumOfSMA = 1_000 -const MaxNumOfSMATruncateSize = 500 +const MaxNumOfSMA = 5_000 +const MaxNumOfSMATruncateSize = 100 var zeroTime time.Time @@ -52,7 +52,7 @@ func (inc *SMA) calculateAndUpdate(kLines []types.KLine) { inc.Values.Push(sma) if len(inc.Values) > MaxNumOfSMA { - inc.Values = inc.Values[MaxNumOfSMATruncateSize:] + inc.Values = inc.Values[MaxNumOfSMATruncateSize - 1:] } inc.EndTime = kLines[index].EndTime