-
-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathchaikinMoneyFlow.ts
More file actions
60 lines (52 loc) · 1.46 KB
/
Copy pathchaikinMoneyFlow.ts
File metadata and controls
60 lines (52 loc) · 1.46 KB
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
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts
import { divide, multiply, subtract } from '../../helper/numArray';
import { msum } from '../trend/movingSum';
/**
* Optional configuration of CMF parameters.
*/
export interface CMFConfig {
period?: number;
}
/**
* The default configuration of CMF.
*/
export const CMFDefaultConfig: Required<CMFConfig> = {
period: 20,
};
/**
* The Chaikin Money Flow (CMF) measures the amount of money flow volume
* over a given period.
*
* Money Flow Multiplier = ((Closing - Low) - (High - Closing)) / (High - Low)
* Money Flow Volume = Money Flow Multiplier * Volume
* Chaikin Money Flow = Sum(20, Money Flow Volume) / Sum(20, Volume)
*
* @param highs high values.
* @param lows low values.
* @param closings closing values.
* @param volumes volume values.
* @param config configuration.
* @returns cmf values.
*/
export function cmf(
highs: number[],
lows: number[],
closings: number[],
volumes: number[],
config: CMFConfig = {}
): number[] {
const { period } = { ...CMFDefaultConfig, ...config };
const moneyFlowMultipler = divide(
subtract(subtract(closings, lows), subtract(highs, closings)),
subtract(highs, lows)
);
const moneyFlowVolume = multiply(moneyFlowMultipler, volumes);
const result = divide(
msum(moneyFlowVolume, { period }),
msum(volumes, { period })
);
return result;
}
// Export full name
export { cmf as chaikinMoneyFlow };