Skip to content

Commit

Permalink
fix ewma truncation
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Dec 21, 2021
1 parent 53f6ea6 commit 8b93aee
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/indicator/ewma.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func (inc *EWMA) calculateAndUpdate(allKLines []types.KLine) {
// for the first value, we should use the close price
inc.Values = []float64{priceF(allKLines[0])}
} else {
if len(inc.Values) >= MaxNumOfEWMA {
inc.Values = inc.Values[MaxNumOfEWMATruncateSize-1:]
}

fromNthK = len(inc.Values)

// update ewma with the existing values
Expand All @@ -73,10 +77,6 @@ func (inc *EWMA) calculateAndUpdate(allKLines []types.KLine) {
}
}

if len(inc.Values) >= MaxNumOfEWMA {
inc.Values = inc.Values[MaxNumOfEWMATruncateSize-1:]
}

for i := fromNthK; i < dataLen; i++ {
var k = allKLines[i]
var ewma = priceF(k)*multiplier + (1-multiplier)*inc.Values[i-1]
Expand Down

0 comments on commit 8b93aee

Please sign in to comment.