-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
accumulationDistribution.ts
47 lines (40 loc) · 1.11 KB
/
accumulationDistribution.ts
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
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts
import { divide, multiply, subtract } from '../../helper/numArray';
/**
* Accumulation/Distribution Indicator (A/D). Cumulative indicator
* that uses volume and price to assess whether a stock is
* being accumulated or distributed.
*
* MFM = ((Closing - Low) - (High - Closing)) / (High - Low)
* MFV = MFM * Period Volume
* AD = Previous AD + CMFV
*
* @param highs high values.
* @param lows low values.
* @param closings closing values.
* @param volume volume values.
* @return ad values.
*/
export function ad(
highs: number[],
lows: number[],
closings: number[],
volume: number[]
): number[] {
const mfm = divide(
subtract(subtract(closings, lows), subtract(highs, closings)),
subtract(highs, lows)
);
const mfv = multiply(mfm, volume);
const result = new Array<number>(mfv.length);
for (let i = 0; i < result.length; i++) {
result[i] = mfv[i];
if (i > 0) {
result[i] += result[i - 1];
}
}
return result;
}
// Export full name
export { ad as accumulationDistribution };