diff --git a/pkg/indicator/ewma.go b/pkg/indicator/ewma.go index 897f92040..54f6a0c1a 100644 --- a/pkg/indicator/ewma.go +++ b/pkg/indicator/ewma.go @@ -9,6 +9,9 @@ import ( "github.com/c9s/bbgo/pkg/types" ) +const MaxEWMAValues = 1_000 +const EWMAValueTruncateSize = 500 + //go:generate callbackgen -type EWMA type EWMA struct { types.IntervalWindow @@ -24,6 +27,8 @@ func (inc *EWMA) Update(value float64) { if len(inc.Values) == 0 { inc.Values.Push(value) return + } else if len(inc.Values) > MaxEWMAValues { + inc.Values = inc.Values[EWMAValueTruncateSize:] } ema := (1-multiplier)*inc.Last() + multiplier*value diff --git a/pkg/indicator/sma.go b/pkg/indicator/sma.go index aa5a4a557..0533a0d92 100644 --- a/pkg/indicator/sma.go +++ b/pkg/indicator/sma.go @@ -9,6 +9,9 @@ import ( "github.com/c9s/bbgo/pkg/types" ) +const MaxSMAValues = 1_000 +const SMAValueTruncateSize = 500 + var zeroTime time.Time //go:generate callbackgen -type SMA @@ -44,6 +47,11 @@ func (inc *SMA) calculateAndUpdate(kLines []types.KLine) { return } inc.Values.Push(sma) + + if len(inc.Values) > MaxSMAValues { + inc.Values = inc.Values[SMAValueTruncateSize:] + } + inc.EndTime = kLines[index].EndTime inc.EmitUpdate(sma)