UNPKG

stock-indicator

Version:

Stock Indicator Library

29 lines (27 loc) 1 kB
import { funEMA, funRound, TMixed, checkArrayOfNumbers, checkNumber, } from "../common/index"; /** * - Exponential Moving Average (EMA) * @param {number[]} CLOSE - closing prices of the stock * @param {number} M1 - number of periods to calculate the EMA,must be greater than 1 and less than the length of the CLOSE array,default is 12 * @param {number} M2 - number of periods to calculate the initial EMA, default is 1,must be less than N,default is 50 * @returns {{ EMA: TMixed[] }} - object with the EMA values,rounded to 3 decimal places */ export function EXPMA( CLOSE: number[], M1: number = 12, M2: number = 50 ): { EMA1: TMixed[]; EMA2: TMixed[] } { // - check input data checkArrayOfNumbers(CLOSE, "CLOSE"); checkNumber(M1, 2, CLOSE, "M1", "CLOSE"); checkNumber(M2, 2, CLOSE, "M2", "CLOSE"); const EMA1 = funEMA(CLOSE, M1, 1).map((item) => funRound(item, 3)); const EMA2 = funEMA(CLOSE, M2, 1).map((item) => funRound(item, 3)); return { EMA1, EMA2 }; }