-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathchaikinMoneyFlowStrategy.ts
44 lines (40 loc) · 1.12 KB
/
chaikinMoneyFlowStrategy.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 {
CMFConfig,
CMFDefaultConfig,
cmf,
} from '../../indicator/volume/chaikinMoneyFlow';
import { Action } from '../action';
import { Asset } from '../asset';
/**
* The chaikin money flow strategy uses the cmf values that are generated
* by the Chaikin Money Flow (CMF) indicator function to provide a BUY
* action when cmf is less than zero, a SELL action when cmf is
* greather than zero, a HOLD action otherwise.
*
* @param asset asset object.
* @param config configuration.
* @returns strategy actions.
*/
export function cmfStrategy(asset: Asset, config: CMFConfig = {}): Action[] {
const strategyConfig = { ...CMFDefaultConfig, ...config };
const result = cmf(
asset.highs,
asset.lows,
asset.closings,
asset.volumes,
strategyConfig
);
return result.map((value) => {
if (value < 0) {
return Action.BUY;
} else if (value > 0) {
return Action.SELL;
} else {
return Action.HOLD;
}
});
}
// Export full name
export { cmfStrategy as chaikinMoneyFlowStrategy };