diff --git a/plot/indicator/cci.go b/plot/indicator/cci.go new file mode 100644 index 00000000..4f19f3ed --- /dev/null +++ b/plot/indicator/cci.go @@ -0,0 +1,47 @@ +package indicator + +import ( + "fmt" + "github.com/markcheno/go-talib" + "github.com/rodrigo-brito/ninjabot/model" + "github.com/rodrigo-brito/ninjabot/plot" + "time" +) + +func Cci(period int, color string) plot.Indicator { + return &cci{ + Period: period, + Color: color, + } +} + +type cci struct { + Period int + Color string + Values model.Series + Time []time.Time +} + +func (c cci) Name() string { + return fmt.Sprintf("CCI(%d)", c.Period) +} + +func (c cci) Overlay() bool { + return false +} + +func (c *cci) Load(dataframe *model.Dataframe) { + c.Values = talib.Cci(dataframe.High, dataframe.Low, dataframe.Close, c.Period) + c.Time = dataframe.Time +} + +func (c cci) Metrics() []plot.IndicatorMetric { + return []plot.IndicatorMetric{ + { + Color: c.Color, + Style: "line", + Values: c.Values, + Time: c.Time, + }, + } +}