UNPKG

stock-indicator

Version:

Stock Indicator Library

34 lines 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VR = VR; const common_1 = require("../common"); function VR(CLOSE, VOL, N = 26, M = 6) { // check input (0, common_1.checkArrayOfNumbers)(CLOSE, "CLOSE"); (0, common_1.checkArrayOfNumbers)(VOL, "VOL"); (0, common_1.checkNumber)(N, 1, CLOSE, "N", "CLOSE"); (0, common_1.checkNumber)(M, 1, CLOSE, "M", "CLOSE"); // TH:=SUM(IF(CLOSE>REF(CLOSE,1),VOL,0),N); const TH = (0, common_1.funMS)([ null, ...CLOSE.slice(1).map((v, i) => ((0, common_1.aGtB)(v, CLOSE[i]) ? VOL[i + 1] : 0)), ], N); // TL:=SUM(IF(CLOSE<REF(CLOSE,1),VOL,0),N); const TL = (0, common_1.funMS)([ null, ...CLOSE.slice(1).map((v, i) => ((0, common_1.aLtB)(v, CLOSE[i]) ? VOL[i + 1] : 0)), ], N); // TQ:=SUM(IF(CLOSE=REF(CLOSE,1),VOL,0),N); const TQ = (0, common_1.funMS)([ null, ...CLOSE.slice(1).map((v, i) => ((0, common_1.aEqB)(v, CLOSE[i]) ? VOL[i + 1] : 0)), ], N); // VR:100*(TH*2+TQ)/(TL*2+TQ); const VR = TH.map((v, i) => v === null || TL[i] === null || TQ[i] === null ? null : (100 * (v * 2 + TQ[i])) / (TL[i] * 2 + TQ[i])).map((v) => (0, common_1.funRound)(v, 3)); // MAVR:MA(VR,M); const MAVR = (0, common_1.funMA)(VR, M).map((v) => (0, common_1.funRound)(v, 3)); return { VR, MAVR }; } //# sourceMappingURL=vr.js.map