stock-indicator
Version:
Stock Indicator Library
27 lines • 1.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DMA = DMA;
const common_1 = require("../common");
/**
* DMA - Different of Moving Average
* @param {number} CLOSE - closing prices of the stock
* @param {number} N1 - number of periods for the first moving average, must be greater than 1 and less than or equal to the length of the CLOSE array,default is 10
* @param {number} N2 - number of periods for the second moving average, must be greater than N1 and less than or equal to the length of the CLOSE array,default is 50
* @param {number} M - number of periods for the moving average of the DIF, must be greater than 1 and less than or equal to the length of the DIF array,default is 10
* @returns {{DIF: TMixed[], DIFMA: TMixed[]}} - DIF and DIFMA arrays, DIFMA is the moving average of the DIF array
*/
function DMA(CLOSE, N1 = 10, N2 = 50, M = 10) {
// - check input data
(0, common_1.checkArrayOfNumbers)(CLOSE, "CLOSE");
(0, common_1.checkNumber)(N1, 2, CLOSE, "N1", "CLOSE");
(0, common_1.checkNumber)(N1, N1, CLOSE, "N2", "CLOSE");
(0, common_1.checkNumber)(M, 2, N2, "M", "N2");
const maN1 = (0, common_1.funMA)(CLOSE, N1);
const maN2 = (0, common_1.funMA)(CLOSE, N2);
const DIF = maN1.map((item, index) => item !== null && maN2[index] !== null
? (0, common_1.funRound)(item - maN2[index], 3)
: null);
const DIFMA = (0, common_1.funMA)(DIF, M).map((item) => (0, common_1.funRound)(item, 3));
return { DIF, DIFMA };
}
//# sourceMappingURL=dma.js.map