Skip to content

Commit

Permalink
feat(chart): include CCI indicator (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertKwiatkowski authored Mar 20, 2022
1 parent 4c7e4b7 commit 108278b
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions plot/indicator/cci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package indicator

import (
"fmt"
"time"

"github.com/rodrigo-brito/ninjabot/model"
"github.com/rodrigo-brito/ninjabot/plot"

"github.com/markcheno/go-talib"
)

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.Period:]
c.Time = dataframe.Time[c.Period:]
}

func (c cci) Metrics() []plot.IndicatorMetric {
return []plot.IndicatorMetric{
{
Color: c.Color,
Style: "line",
Values: c.Values,
Time: c.Time,
},
}
}

0 comments on commit 108278b

Please sign in to comment.