-
Notifications
You must be signed in to change notification settings - Fork 143
/
indicator_cci.go
25 lines (20 loc) · 887 Bytes
/
indicator_cci.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
package techan
import "github.com/sdcoffey/big"
type commidityChannelIndexIndicator struct {
series *TimeSeries
window int
}
// NewCCIIndicator Returns a new Commodity Channel Index Indicator
// http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:commodity_channel_index_cci
func NewCCIIndicator(ts *TimeSeries, window int) Indicator {
return commidityChannelIndexIndicator{
series: ts,
window: window,
}
}
func (ccii commidityChannelIndexIndicator) Calculate(index int) big.Decimal {
typicalPrice := NewTypicalPriceIndicator(ccii.series)
typicalPriceSma := NewSimpleMovingAverage(typicalPrice, ccii.window)
meanDeviation := NewMeanDeviationIndicator(NewClosePriceIndicator(ccii.series), ccii.window)
return typicalPrice.Calculate(index).Sub(typicalPriceSma.Calculate(index)).Div(meanDeviation.Calculate(index).Mul(big.NewFromString("0.015")))
}