forked from iamjinlei/go-tart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathad.go
73 lines (66 loc) · 2.75 KB
/
ad.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package tart
// Developed by Marc Chaikin, the Accumulation Distribution
// Line is a volume-based indicator designed to measure the
// cumulative flow of money into and out of a security.
// Chaikin originally referred to the indicator as the
// Cumulative Money Flow Line. As with cumulative indicators,
// the Accumulation Distribution Line is a running total of
// each period's Money Flow Volume. First, a multiplier is
// calculated based on the relationship of the close to the
// high-low range. Second, the Money Flow Multiplier is
// multiplied by the period's volume to come up with a
// Money Flow Volume. A running total of the Money Flow
// Volume forms the Accumulation Distribution Line.
// Chartists can use this indicator to affirm a security's
// underlying trend or anticipate reversals when the
// indicator diverges from the security price.
// https://school.stockcharts.com/doku.php?id=technical_indicators:accumulation_distribution_line
// https://www.investopedia.com/terms/a/accumulationdistribution.asp
// https://www.fidelity.com/learning-center/trading-investing/technical-analysis/technical-indicator-guide/accumulation-distribution
type Ad struct {
ad float64
}
func NewAd() *Ad {
return &Ad{
ad: 0,
}
}
func (a *Ad) Update(h, l, c, v float64) float64 {
h2l := h - l
if h2l > 0.0 {
a.ad += (((c - l) - (h - c)) / h2l) * v
}
return a.ad
}
func (a *Ad) InitPeriod() int64 {
return 0
}
func (a *Ad) Valid() bool {
return true
}
// Developed by Marc Chaikin, the Accumulation Distribution
// Line is a volume-based indicator designed to measure the
// cumulative flow of money into and out of a security.
// Chaikin originally referred to the indicator as the
// Cumulative Money Flow Line. As with cumulative indicators,
// the Accumulation Distribution Line is a running total of
// each period's Money Flow Volume. First, a multiplier is
// calculated based on the relationship of the close to the
// high-low range. Second, the Money Flow Multiplier is
// multiplied by the period's volume to come up with a
// Money Flow Volume. A running total of the Money Flow
// Volume forms the Accumulation Distribution Line.
// Chartists can use this indicator to affirm a security's
// underlying trend or anticipate reversals when the
// indicator diverges from the security price.
// https://school.stockcharts.com/doku.php?id=technical_indicators:accumulation_distribution_line
// https://www.investopedia.com/terms/a/accumulationdistribution.asp
// https://www.fidelity.com/learning-center/trading-investing/technical-analysis/technical-indicator-guide/accumulation-distribution
func AdArr(h, l, c, v []float64) []float64 {
out := make([]float64, len(c))
a := NewAd()
for i := 0; i < len(c); i++ {
out[i] = a.Update(h[i], l[i], c[i], v[i])
}
return out
}