stock-indicator
Version:
Stock Indicator Library
28 lines • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EMV = EMV;
const common_1 = require("../common");
function EMV(HIGH, LOW, VOL, N = 14, M = 9) {
// check input
(0, common_1.checkArrayOfNumbers)(HIGH, "HIGH");
(0, common_1.checkArrayOfNumbers)(LOW, "LOW");
(0, common_1.checkArrayOfNumbers)(VOL, "VOL");
(0, common_1.checkNumber)(N, 2, HIGH, "N", "HIGH");
(0, common_1.checkNumber)(M, 2, HIGH, "M", "HIGH");
// calculate
// VOLUME:=MA(VOL,N)/VOL;
const VOLUME = (0, common_1.funMA)(VOL, N).map((item, index) => item === null ? null : item / VOL[index]);
// MID:=100*(HIGH+LOW-REF(HIGH+LOW,1))/(HIGH+LOW);
const MID = [
null,
...HIGH.slice(1).map((item, index) => ((item - HIGH[index] + LOW[index + 1] - LOW[index]) /
(item + LOW[index + 1])) *
100),
];
// EMV:MA(MID*VOLUME*(HIGH-LOW)/MA(HIGH-LOW,N),N);
const EMV = (0, common_1.funMA)((0, common_1.funArrDiv)((0, common_1.funArrMul)(MID, (0, common_1.funArrMul)(VOLUME, (0, common_1.funArrSub)(HIGH, LOW))), (0, common_1.funMA)((0, common_1.funArrSub)(HIGH, LOW), N)), N);
// MAEMV:MA(EMV,M);
const MAEMV = (0, common_1.funMA)(EMV, M).map((v) => (0, common_1.funRound)(v, 3));
return { EMV: EMV.map((v) => (0, common_1.funRound)(v, 3)), MAEMV };
}
//# sourceMappingURL=emv.js.map