-
Notifications
You must be signed in to change notification settings - Fork 41
/
chandelierExit.src.js
54 lines (47 loc) · 1.43 KB
/
chandelierExit.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
var shortLabel,
longLabel;
function getRunUpCount (periods) {
return periods * 2;
}
function getBufferSize (periods) {
return periods;
}
function validate (periods, multiplier) {
if (typeof periods !== "number") {
error("Chandelier Exit periods must be a number");
}
if (periods % 1 !== 0) {
error("Chandelier Exit periods must be an integer");
}
if (periods > 100) {
error("Chandelier Exit maximum periods is 100");
}
if (periods <= 0) {
error("Chandelier Exit periods must be greater than zero");
}
if (typeof multiplier !== "number") {
error("Chandelier Exit multiplier must be a number");
}
if (multiplier <= 0) {
error("Chandelier Exit multiplier must be greater than zero");
}
}
function onStart (periods, multiplier) {
shortLabel = "chandelierExit(" + periods + "," + multiplier + ") Short";
longLabel = "chandelierExit(" + periods + "," + multiplier + ") Long";
}
function onIntervalClose (periods, multiplier) {
var averageTrueRange = atr(periods),
closes = prices(periods),
highestHigh = Math.highest(closes),
lowestLow = Math.lowest(closes);
return [{
name: shortLabel,
value: lowestLow + (averageTrueRange * multiplier),
envelope: false
}, {
name: longLabel,
value: highestHigh - (averageTrueRange * multiplier),
envelope: false
}];
}