-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathemv.src.js
61 lines (48 loc) · 1.38 KB
/
emv.src.js
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
61
var previousMidpoint,
eoms = [];
function getRunUpCount (periods) {
return periods;
}
function getBufferSize (periods) {
return 0;
}
function onStart (periods) {
if (typeof periods !== "number") {
error("Ease of Movement periods must be a number");
}
if (periods % 1 !== 0) {
error("Ease of Movement periods must be an integer");
}
if (periods > 100) {
error("Ease of Movement maximum periods is 100");
}
if (periods <= 0) {
error("Ease of Movement periods must be greater than zero");
}
}
function onIntervalClose (periods) {
var midpoint = (HIGH + LOW) / 2,
distanceMoved,
boxRatio,
eom;
if (previousMidpoint === undefined) {
previousMidpoint = (HIGH + LOW) / 2;
return null;
}
distanceMoved = midpoint - previousMidpoint;
// TODO Volume is divided by 100m to make relevant to other numbers (for stock volume)
// Probably then need to adjust depending on instrument tick size
boxRatio = (VOLUME / 100000000) / (HIGH - LOW);
eom = distanceMoved / boxRatio;
previousMidpoint = midpoint;
eoms.push(eom);
if (eoms.length < periods) {
return null;
} else if (eoms.length > periods){
eoms.shift();
}
return {
overlay: false,
value: Math.average(eoms)
};
}