-
Notifications
You must be signed in to change notification settings - Fork 1
/
rsi.go
57 lines (46 loc) · 904 Bytes
/
rsi.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
package indicator
import (
"fmt"
"time"
"github.com/ezquant/azbot/azbot/model"
"github.com/ezquant/azbot/azbot/plot"
"github.com/markcheno/go-talib"
)
func RSI(period int, color string) plot.Indicator {
return &rsi{
Period: period,
Color: color,
}
}
type rsi struct {
Period int
Color string
Values model.Series[float64]
Time []time.Time
}
func (e rsi) Warmup() int {
return e.Period
}
func (e rsi) Name() string {
return fmt.Sprintf("RSI(%d)", e.Period)
}
func (e rsi) Overlay() bool {
return false
}
func (e *rsi) Load(dataframe *model.Dataframe) {
if len(dataframe.Time) < e.Period {
return
}
e.Values = talib.Rsi(dataframe.Close, e.Period)[e.Period:]
e.Time = dataframe.Time[e.Period:]
}
func (e rsi) Metrics() []plot.IndicatorMetric {
return []plot.IndicatorMetric{
{
Color: e.Color,
Style: "line",
Values: e.Values,
Time: e.Time,
},
}
}