-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
accumulationDistribution.ts
44 lines (38 loc) · 1.05 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
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts
import { divide, multiply, substract } 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 accumulationDistribution(
highs: number[],
lows: number[],
closings: number[],
volume: number[]
): number[] {
const mfm = divide(
substract(substract(closings, lows), substract(highs, closings)),
substract(highs, lows)
);
const mfv = multiply(mfm, volume);
const ad = new Array<number>(mfv.length);
for (let i = 0; i < ad.length; i++) {
ad[i] = mfv[i];
if (i > 0) {
ad[i] += ad[i - 1];
}
}
return ad;
}