Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Slow Stochastic Oscillator #896

Merged
merged 1 commit into from
Dec 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/_codemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ module.exports = {
'vma': require('./vma'),
'lrc': require('./lrc'),
'adx': require('./adx'),
'vwap': require('./vwap')
'vwap': require('./vwap'),
'slow_stochastic': require('./slow_stochastic')
}
24 changes: 24 additions & 0 deletions lib/slow_stochastic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = function container (get, set, clear) {
return function slow_stochastic (s, key, k, d) {
if (!k) k = 14;
if (!d) d = 3;
if (s.lookback.length >= k + d * 2) {
let stochK = [];
for (let j = 0; j < d; j++) {
let stochs = [];
for (let i = 0; i < d; i++)
stochs.push((function(x, length) {
let low = [], high = [];
x.slice(0, length).forEach(function (period) {
low.push(period.low);
high.push(period.high);
});
return 100 * (x[0].close - Math.min(...low)) / (Math.max(...high) - Math.min(...low));
})(s.lookback.slice(i+j), k));
stochK.push(stochs.reduce((sum, cur) => { return sum + cur; }, 0) / d);
}
let stochD = stochK.reduce((sum, cur) => { return sum + cur; }, 0) / d;
s.period[key] = { K: stochK[0], D: stochD };
}
}
}