diff --git a/pkg/indicator/pivot.go b/pkg/indicator/pivot.go index 71a6f35f6..ccc1322e2 100644 --- a/pkg/indicator/pivot.go +++ b/pkg/indicator/pivot.go @@ -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 { @@ -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 } @@ -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:] @@ -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) { diff --git a/pkg/indicator/pivot_callbacks.go b/pkg/indicator/pivot_callbacks.go index 1fb7081d7..4c3a90ccf 100644 --- a/pkg/indicator/pivot_callbacks.go +++ b/pkg/indicator/pivot_callbacks.go @@ -5,11 +5,11 @@ package indicator import () func (inc *Pivot) OnUpdate(cb func(valueLow float64, valueHigh float64)) { - inc.UpdateCallbacks = append(inc.UpdateCallbacks, cb) + inc.updateCallbacks = append(inc.updateCallbacks, cb) } func (inc *Pivot) EmitUpdate(valueLow float64, valueHigh float64) { - for _, cb := range inc.UpdateCallbacks { + for _, cb := range inc.updateCallbacks { cb(valueLow, valueHigh) } }