UNPKG

stock-indicator

Version:

Stock Indicator Library

47 lines 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OBV = OBV; const common_1 = require("../common"); /** * * @param CLOSE * @param VOL * @param M * @returns * 传入的VOL 单位为股,需要转换为手 */ function OBV(CLOSE, VOL, M = 30) { // check input data (0, common_1.checkArrayOfNumbers)(CLOSE, "CLOSE"); (0, common_1.checkArrayOfNumbers)(VOL, "VOL"); (0, common_1.checkNumber)(M, 2, CLOSE, "M", "CLOSE"); VOL = VOL.map((v) => v / 100); // calculate OBV and MAOBV // VA:=IF(CLOSE>REF(CLOSE,1),VOL,-VOL); const VA = [ null, ...CLOSE.slice(1).map((v, i) => (0, common_1.aGtB)(v, CLOSE[i]) ? VOL[i + 1] : -VOL[i + 1]), ]; // OBV:SUM(IF(CLOSE=REF(CLOSE,1),0,VA),0); const OBV = [ null, ...CLOSE.slice(1).map((v, i) => { return (0, common_1.aEqB)(v, CLOSE[i]) ? 0 : VA[i + 1]; }), ].reduce((acc, cur, i) => { var _a; if (i === 0) { acc.push(null); return acc; } acc.push((cur !== null && cur !== void 0 ? cur : 0) + ((_a = acc[i - 1]) !== null && _a !== void 0 ? _a : 0)); return acc; }, []); // MAOBV:MA(OBV,M); const MAOBV = (0, common_1.funMA)(OBV, M).map((v) => (0, common_1.funRound)(v, 3)); return { OBV: OBV.map((v) => (0, common_1.funRound)(v, 3)), MAOBV, }; } //# sourceMappingURL=obv.js.map