-
Notifications
You must be signed in to change notification settings - Fork 142
/
indicator_bollinger_band.go
33 lines (28 loc) · 1.1 KB
/
indicator_bollinger_band.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
package techan
import "github.com/sdcoffey/big"
type bbandIndicator struct {
ma Indicator
stdev Indicator
muladd big.Decimal
}
// NewBollingerUpperBandIndicator a a derivative indicator which returns the upper bound of a bollinger band
// on the underlying indicator
func NewBollingerUpperBandIndicator(indicator Indicator, window int, sigma float64) Indicator {
return bbandIndicator{
ma: NewSimpleMovingAverage(indicator, window),
stdev: NewWindowedStandardDeviationIndicator(indicator, window),
muladd: big.NewDecimal(sigma),
}
}
// NewBollingerLowerBandIndicator returns a a derivative indicator which returns the lower bound of a bollinger band
// on the underlying indicator
func NewBollingerLowerBandIndicator(indicator Indicator, window int, sigma float64) Indicator {
return bbandIndicator{
ma: NewSimpleMovingAverage(indicator, window),
stdev: NewWindowedStandardDeviationIndicator(indicator, window),
muladd: big.NewDecimal(-sigma),
}
}
func (bbi bbandIndicator) Calculate(index int) big.Decimal {
return bbi.ma.Calculate(index).Add(bbi.stdev.Calculate(index).Mul(bbi.muladd))
}