index.js
function ema(close, n = 5) {
    let len = close.length
    let result = []
    if (len === 0 || n <= 0) {
        return result
    }
    let alpha = 2 / (n + 1)
    let avg = close[0]
    result.push(avg)
    for (let i = 1; i < len; i++) {
        avg = alpha * close[i] + (1 - alpha) * avg
        result.push(avg)
    }
    return result
}
function ema(close, n = 5) {
    let len = close.length
    let result = []
    if (len === 0 || n <= 0) {
        return result
    }
    let alpha = 2 / (n + 1)
    let avg = close[0]
    result.push(avg)
    for (let i = 1; i < len; i++) {
        avg = alpha * close[i] + (1 - alpha) * avg
        result.push(avg)
    }
    return result
}
function ema ( close , n = 5 ) { let len = close . length let result = [ ] if ( len === 0 || n <= 0 ) { return result } let alpha = 2 / ( n + 1 ) let avg = close [ 0 ] result . push ( avg ) for ( let i = 1 ; i < len ; i ++ ) { avg = alpha * close [ i ] + ( 1 - alpha ) * avg result . push ( avg ) } return result }
Exponential moving average

alpha = 2 / (N + 1)
Exponential moving average