-
-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy patheaseOfMovement.ts
More file actions
57 lines (51 loc) · 1.36 KB
/
Copy patheaseOfMovement.ts
File metadata and controls
57 lines (51 loc) · 1.36 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
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts
import {
add,
changes,
divide,
divideBy,
subtract,
} from '../../helper/numArray';
import { sma } from '../trend/simpleMovingAverage';
/**
* Optional configuration of EMV parameters.
*/
export interface EMVConfig {
period?: number;
}
/**
* The default configuration of EMV.
*/
export const EMVDefaultConfig: Required<EMVConfig> = {
period: 14,
};
/**
* The Ease of Movement (EMV) is a volume based oscillator measuring
* the ease of price movement.
*
* Distance Moved = ((High + Low) / 2) - ((Priod High + Prior Low) /2)
* Box Ratio = ((Volume / 100000000) / (High - Low))
* EMV(1) = Distance Moved / Box Ratio
* EMV(14) = SMA(14, EMV(1))
*
* @param highs high values.
* @param lows low values.
* @param volumes volume values.
* @param config configuration.
* @return ease of movement values.
*/
export function emv(
highs: number[],
lows: number[],
volumes: number[],
config: EMVConfig = {}
): number[] {
const { period } = { ...EMVDefaultConfig, ...config };
const distanceMoved = changes(1, divideBy(2, add(highs, lows)));
const boxRatio = divide(divideBy(100000000, volumes), subtract(highs, lows));
const result = sma(divide(distanceMoved, boxRatio), { period });
return result;
}
// Export full name
export { emv as easeOfMovement };