-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathstochRsi.src.js
43 lines (35 loc) · 920 Bytes
/
stochRsi.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
var RSIs = [];
function getStudyAxisConfig () {
return {
tickPositions: [0, 0.2, 0.5, 0.8, 1]
};
}
function validate (periods) {
if (typeof periods !== "number") {
error("StochRSI periods must be a number");
}
if (periods % 1 !== 0) {
error("StochRSI periods must be an integer");
}
if (periods > 100) {
error("StochRSI maximum periods is 100");
}
if (periods <= 0) {
error("StochRSI periods must be greater than zero");
}
}
function onIntervalClose (periods) {
var RSI = rsi(periods),
RSIPeriodLow;
RSIs.push(RSI);
if (RSIs.length < periods) {
return null;
} else if (RSIs.length > periods) {
RSIs.shift();
}
RSIPeriodLow = Math.min.apply(null, RSIs);
return {
overlay: false,
value: (RSI - RSIPeriodLow) / (Math.max.apply(null, RSIs) - RSIPeriodLow)
};
}