-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathnatr.go
46 lines (38 loc) · 868 Bytes
/
natr.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
41
42
43
44
45
46
package tart
// Normalized Average True Range (NATR) attempts to normalize
// the average true range values across instruments by using
// the closing price.
type Natr struct {
n int64
atr *Atr
}
func NewNatr(n int64) *Natr {
return &Natr{
n: n,
atr: NewAtr(n),
}
}
func (a *Natr) Update(h, l, c float64) float64 {
tr := a.atr.Update(h, l, c)
if c == 0 {
return 0
}
return tr / c * 100.0
}
func (a *Natr) InitPeriod() int64 {
return a.atr.InitPeriod()
}
func (a *Natr) Valid() bool {
return a.atr.Valid()
}
// Normalized Average True Range (NATR) attempts to normalize
// the average true range values across instruments by using
// the closing price.
func NatrArr(h, l, c []float64, n int64) []float64 {
out := make([]float64, len(c))
a := NewNatr(n)
for i := 0; i < len(c); i++ {
out[i] = a.Update(h[i], l[i], c[i])
}
return out
}