Skip to content

Commit

Permalink
fix pivot indicator: filter out zero lows and highs
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jun 10, 2022
1 parent e60e217 commit fba0a20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions pkg/indicator/pivot.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Pivot struct {

EndTime time.Time

UpdateCallbacks []func(valueLow, valueHigh float64)
updateCallbacks []func(valueLow, valueHigh float64)
}

func (inc *Pivot) LastLow() float64 {
Expand All @@ -38,7 +38,7 @@ func (inc *Pivot) LastHigh() float64 {
return inc.Highs[len(inc.Highs)-1]
}

func (inc *Pivot) calculateAndUpdate(klines []types.KLine) {
func (inc *Pivot) Update(klines []types.KLine) {
if len(klines) < inc.Window {
return
}
Expand All @@ -59,8 +59,12 @@ func (inc *Pivot) calculateAndUpdate(klines []types.KLine) {
return
}

inc.Lows.Push(l)
inc.Highs.Push(h)
if l > 0.0 {
inc.Lows.Push(l)
}
if h > 0.0 {
inc.Highs.Push(h)
}

if len(inc.Lows) > MaxNumOfVOL {
inc.Lows = inc.Lows[MaxNumOfVOLTruncateSize-1:]
Expand All @@ -80,7 +84,7 @@ func (inc *Pivot) handleKLineWindowUpdate(interval types.Interval, window types.
return
}

inc.calculateAndUpdate(window)
inc.Update(window)
}

func (inc *Pivot) Bind(updater KLineWindowUpdater) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/indicator/pivot_callbacks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fba0a20

Please sign in to comment.