Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(chart): include CCI indicator #114

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
},
}
}