-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfloat64.go
29 lines (25 loc) · 822 Bytes
/
float64.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
package ad
// AD represents the state of an Accumulation Distribution Line.
type AD struct {
prev float64
}
// Input is the required input to calculate a point on the Accumulation Distribution Line.
type Input struct {
Close float64
Low float64
High float64
Volume float64
}
// New creates a new AD data structure and returns the initial result.
func New(initial Input) (ad *AD, result float64) {
ad = &AD{}
return ad, ad.Calculate(initial)
}
// Calculate produces the next point on the Accumulation Distribution Line given the current period's information.
func (ad *AD) Calculate(next Input) float64 {
if next.High == next.Low || next.Volume == 0 {
return ad.prev
}
ad.prev = (((next.Close - next.Low) - (next.High - next.Close)) / (next.High - next.Low) * next.Volume) + ad.prev
return ad.prev
}