UNPKG

jesse-indicators

Version:

A Technical indicator library for TypeScript.

24 lines 973 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const SMA_1 = __importDefault(require("../SMA")); function stoch(values, period) { if (values.length !== period) { throw new Error(`Number of values(${values.length}) must be the same as the K period(${period}).`); } const lowest = Math.min(...values); const highest = Math.max(...values); const current = values[values.length - 1]; return ((current - lowest) / (highest - lowest)) * 100; } exports.stoch = stoch; function smoothedStoch(stochs, kPeriod) { if (stochs.length !== kPeriod) { throw new Error(`Number of stochs(${stochs.length}) must be the same as the K period(${kPeriod}).`); } return SMA_1.default(stochs, kPeriod); } exports.smoothedStoch = smoothedStoch; //# sourceMappingURL=index.js.map