forked from cinar/indicatorts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforceIndex.ts
38 lines (35 loc) · 982 Bytes
/
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
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts
import { changes, multiply } from '../../helper/numArray';
import { ema } from '../trend/ema';
/**
* 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 period window period.
* @param closings closing values.
* @param volumes volume values.
* @return force index.
*/
export function forceIndex(
period: number,
closings: number[],
volumes: number[]
): number[] {
return ema(period, multiply(changes(1, closings), volumes));
}
/**
* The default Force Index (FI) with window size of 13.
*
* @param closings closing values.
* @param volumes volume values.
* @return force index.
*/
export function defaultForceIndex(
closings: number[],
volumes: number[]
): number[] {
return forceIndex(13, closings, volumes);
}