forked from sdcoffey/techan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
indicator_keltner_channel.go
40 lines (33 loc) · 980 Bytes
/
indicator_keltner_channel.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package techan
import (
"github.com/sdcoffey/big"
)
type keltnerChannelIndicator struct {
ema Indicator
atr Indicator
mul big.Decimal
window int
}
func NewKeltnerChannelUpperIndicator(series *TimeSeries, window int) Indicator {
return keltnerChannelIndicator{
atr: NewAverageTrueRangeIndicator(series, window),
ema: NewEMAIndicator(NewClosePriceIndicator(series), window),
mul: big.ONE,
window: window,
}
}
func NewKeltnerChannelLowerIndicator(series *TimeSeries, window int) Indicator {
return keltnerChannelIndicator{
atr: NewAverageTrueRangeIndicator(series, window),
ema: NewEMAIndicator(NewClosePriceIndicator(series), window),
mul: big.ONE.Neg(),
window: window,
}
}
func (kci keltnerChannelIndicator) Calculate(index int) big.Decimal {
if index <= kci.window-1 {
return big.ZERO
}
coefficient := big.NewFromInt(2).Mul(kci.mul)
return kci.ema.Calculate(index).Add(kci.atr.Calculate(index).Mul(coefficient))
}