-
Notifications
You must be signed in to change notification settings - Fork 43
/
bollingerBandwidth.src.js
39 lines (35 loc) · 1.07 KB
/
bollingerBandwidth.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
function getBufferSize (periods) {
return periods;
}
function validate (periods, deviations) {
if (typeof periods !== "number") {
error("Bollinger Bandwidth periods must be a number");
}
if (periods % 1 !== 0) {
error("Bollinger Bandwidth periods must be an integer");
}
if (periods > 100) {
error("Bollinger Bandwidth maximum periods is 100");
}
if (periods <= 0) {
error("Bollinger Bandwidth periods must be greater than zero");
}
if (typeof deviations !== "number") {
error("Bollinger Bandwidth deviation multiplier must be a number");
}
if (typeof deviations <= 0) {
error("Bollinger Bandwidth deviation multiplier must be greater than zero");
}
}
function onIntervalClose (periods, deviations) {
var closePrices = prices(periods),
SMA = Math.mean(closePrices),
margin = Math.standardDeviation(closePrices) * deviations;
return {
overlay: false,
value: ((margin * 2) / SMA) * 100,
tooltip: {
valueDecimals: 2
}
};
}