Skip to content

Commit

Permalink
indicator/atr: implement LoadK and BindK
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jul 20, 2022
1 parent 0b9d693 commit a821641
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions pkg/indicator/atr.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,29 @@ func (inc *ATR) Length() int {
}

func (inc *ATR) PushK(k types.KLine) {
if inc.EndTime != zeroTime && !k.EndTime.After(inc.EndTime) {
return
}

inc.Update(k.High.Float64(), k.Low.Float64(), k.Close.Float64())
inc.EndTime = k.EndTime.Time()
inc.EmitUpdate(inc.Last())
}

func (inc *ATR) LoadK(allKlines []types.KLine) {
for _, k := range allKlines {
inc.PushK(k)
}
}

func (inc *ATR) BindK(target KLineClosedEmitter, symbol string, interval types.Interval) {
target.OnKLineClosed(types.KLineWith(symbol, interval, inc.PushK))
}

func (inc *ATR) CalculateAndUpdate(kLines []types.KLine) {
for _, k := range kLines {
if inc.EndTime != zeroTime && !k.EndTime.After(inc.EndTime) {
continue
}
inc.PushK(k)
}

inc.EmitUpdate(inc.Last())
inc.EndTime = kLines[len(kLines)-1].EndTime.Time()
}

func (inc *ATR) handleKLineWindowUpdate(interval types.Interval, window types.KLineWindow) {
Expand Down

0 comments on commit a821641

Please sign in to comment.