-
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathpivothigh.go
64 lines (48 loc) · 1.02 KB
/
pivothigh.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package indicator
import (
"time"
"github.com/c9s/bbgo/pkg/datatype/floats"
"github.com/c9s/bbgo/pkg/types"
)
//go:generate callbackgen -type PivotHigh
type PivotHigh struct {
types.SeriesBase
types.IntervalWindow
Highs floats.Slice
Values floats.Slice
EndTime time.Time
updateCallbacks []func(value float64)
}
func (inc *PivotHigh) Length() int {
return inc.Values.Length()
}
func (inc *PivotHigh) Last(i int) float64 {
return inc.Values.Last(i)
}
func (inc *PivotHigh) Update(value float64) {
if len(inc.Highs) == 0 {
inc.SeriesBase.Series = inc
}
inc.Highs.Push(value)
if len(inc.Highs) < inc.Window {
return
}
if inc.RightWindow == nil {
inc.RightWindow = &inc.Window
}
high, ok := calculatePivotHigh(inc.Highs, inc.Window, *inc.RightWindow)
if !ok {
return
}
if high > 0.0 {
inc.Values.Push(high)
}
}
func (inc *PivotHigh) PushK(k types.KLine) {
if k.EndTime.Before(inc.EndTime) {
return
}
inc.Update(k.High.Float64())
inc.EndTime = k.EndTime.Time()
inc.EmitUpdate(inc.Last(0))
}