-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathadxr.go
51 lines (41 loc) · 1.13 KB
/
adxr.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
47
48
49
50
51
package tart
// Average Directional Movement Index Rating (ADXR) is a simple
// average of today’s ADX value and the ADX from N periods ago.
// https://www.fidelity.com/learning-center/trading-investing/technical-analysis/technical-indicator-guide/dmi
type AdxR struct {
n int64
adx *Adx
hist *CBuf
}
func NewAdxR(n int64) *AdxR {
return &AdxR{
n: n,
adx: NewAdx(n),
hist: NewCBuf(n - 1),
}
}
func (a *AdxR) Update(h, l, c float64) float64 {
v := a.adx.Update(h, l, c)
old := a.hist.Append(v)
if a.hist.Size() <= 3*a.n-2 {
return 0
}
return (old + v) / 2.0
}
func (a *AdxR) InitPeriod() int64 {
return 3*a.n - 2
}
func (a *AdxR) Valid() bool {
return a.hist.Size() > a.InitPeriod()
}
// Average Directional Movement Index Rating (ADXR) is a simple
// average of today’s ADX value and the ADX from N periods ago.
// https://www.fidelity.com/learning-center/trading-investing/technical-analysis/technical-indicator-guide/dmi
func AdxRArr(h, l, c []float64, n int64) []float64 {
out := make([]float64, len(c))
a := NewAdxR(n)
for i := 0; i < len(c); i++ {
out[i] = a.Update(h[i], l[i], c[i])
}
return out
}