UNPKG

stock-indicator

Version:

Stock Indicator Library

27 lines 1.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MA = MA; const common_1 = require("../common"); /** * - Moving Average (MA) * @param {number[]} CLOSE - - closing prices of the stock * @param {number} N - - number of periods to calculate the moving average, must be between 2 and the length of the CLOSE array,defaults : 5, 10, 20, 60 * @returns {{ [key: string]: TMixed[] } } - object with the moving averages for each period */ function MA(CLOSE, ...N) { // - check input data (0, common_1.checkArrayOfNumbers)(CLOSE, "CLOSE"); // - set default values for N if (N.length === 0) { N = [5, 10, 20, 60]; } // - check N values N.forEach((item, index) => { (0, common_1.checkNumber)(item, 2, CLOSE, `N[${index}]`, "CLOSE"); }); return N.reduce((acc, cur) => { acc[`MA${cur}`] = (0, common_1.funMA)(CLOSE, cur).map((item) => (0, common_1.funRound)(item, 3)); return acc; }, {}); } //# sourceMappingURL=ma.js.map