-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathforceIndex.ts
44 lines (38 loc) · 1.03 KB
/
forceIndex.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 { changes, multiply } from '../../helper/numArray';
import { ema } from '../trend/exponentialMovingAverage';
/**
* Optional configuration of FI parameters.
*/
export interface FIConfig {
period?: number;
}
/**
* The default configuration of FI.
*/
export const FIDefaultConfig: Required<FIConfig> = {
period: 13,
};
/**
* The Force Index (FI) uses the closing price and the volume to assess
* the power behind a move and identify turning points.
*
* Force Index = EMA(period, (Current - Previous) * Volume)
*
* @param closings closing values.
* @param volumes volume values.
* @param config configuration.
* @return force index.
*/
export function fi(
closings: number[],
volumes: number[],
config: FIConfig = {}
): number[] {
const { period } = { ...FIDefaultConfig, ...config };
const result = ema(multiply(changes(1, closings), volumes), { period });
return result;
}
// Export full name
export { fi as forceIndex };