Skip to content

Commit

Permalink
feat(chart): include CCI indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-Kwiatkowski committed Mar 20, 2022
1 parent 4c7e4b7 commit 176d17f
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions plot/indicator/cci.go
Original file line number Diff line number Diff line change
@@ -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,
},
}
}

0 comments on commit 176d17f

Please sign in to comment.