Skip to content

Commit

Permalink
indicator/till: refactor CalculateAndUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jul 20, 2022
1 parent 9f937f5 commit 2523c22
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions pkg/indicator/till.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,35 @@ func (inc *TILL) Length() int {
var _ types.Series = &TILL{}

func (inc *TILL) PushK(k types.KLine) {
if k.EndTime.Before(inc.e1.EndTime) {
return
}

inc.Update(k.Close.Float64())
inc.EmitUpdate(inc.Last())
}

func (inc *TILL) CalculateAndUpdate(allKLines []types.KLine) {
doable := false
if inc.e1 == nil {
doable = true
}
func (inc *TILL) LoadK(allKLines []types.KLine) {
for _, k := range allKLines {
if !doable && k.EndTime.After(inc.e1.EndTime) {
doable = true
}
inc.PushK(k)
}
}

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

if doable {
func (inc *TILL) CalculateAndUpdate(allKLines []types.KLine) {
if inc.e1 == nil {
for _, k := range allKLines {
inc.PushK(k)
inc.EmitUpdate(inc.Last())
}
} else {
end := len(allKLines)
last := allKLines[end-1]
inc.PushK(last)
}

}

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

0 comments on commit 2523c22

Please sign in to comment.