Skip to content

Commit

Permalink
indicator: rename consts for max ma values
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jun 28, 2021
1 parent 4ccbb82 commit 01bdef5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkg/indicator/ewma.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/c9s/bbgo/pkg/types"
)

const MaxEWMAValues = 1_000
const EWMAValueTruncateSize = 500
const MaxNumOfEWMA = 1_000
const MaxNumOfEWMATruncateSize = 500

//go:generate callbackgen -type EWMA
type EWMA struct {
Expand All @@ -27,8 +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:]
} else if len(inc.Values) > MaxNumOfEWMA {
inc.Values = inc.Values[MaxNumOfEWMATruncateSize:]
}

ema := (1-multiplier)*inc.Last() + multiplier*value
Expand Down
8 changes: 4 additions & 4 deletions pkg/indicator/sma.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/c9s/bbgo/pkg/types"
)

const MaxSMAValues = 1_000
const SMAValueTruncateSize = 500
const MaxNumOfSMA = 1_000
const MaxNumOfSMATruncateSize = 500

var zeroTime time.Time

Expand Down Expand Up @@ -48,8 +48,8 @@ func (inc *SMA) calculateAndUpdate(kLines []types.KLine) {
}
inc.Values.Push(sma)

if len(inc.Values) > MaxSMAValues {
inc.Values = inc.Values[SMAValueTruncateSize:]
if len(inc.Values) > MaxNumOfSMA {
inc.Values = inc.Values[MaxNumOfSMATruncateSize:]
}

inc.EndTime = kLines[index].EndTime
Expand Down

0 comments on commit 01bdef5

Please sign in to comment.