index.js
function kdj(close, high, low, n = 5) {
    let len = close.length
    let k = []
    let d = []
    let j = []
    if (len === 0 || n <= 0) {
        return {k, d, j}
    }
    let ik = 50
    let id = 50
    let ij = 50
    let rsv = (close[0] - low[0]) * 100 / (high[0] - low[0])
    ik = 2 * ik / 3 + rsv / 3
    id = 2 * id / 3 + ik / 3
    ij = 3 * ik - 2 * id
    k.push(ik)
    d.push(id)
    j.push(ij)

    let ln = low[0]
    let hn = high[0]
    for (let i = 1; i < len; i++) {
        if (i < n) {
            if (ln > low[i]) {
                ln = low[i]
            }
            if (hn < high[i]) {
                hn = high[i]
            }
        } else {
            if (ln === low[i - n]) {
                ln = low[i]
                for (let j = 1; j < n; j++) {
                    if (low[i - j] < ln) {
                        ln = low[i - j]
                    }
                }
            } else {
                if (ln > low[i]) {
                    ln = low[i]
                }
            }

            if (hn === high[i - n]) {
                hn = high[i]
                for (let j = 1; j < n; j++) {
                    if (high[i - j] > hn) {
                        hn = high[i - j]
                    }
                }
            } else {
                if (hn < high[i]) {
                    hn = high[i]
                }
            }
        }
        rsv = (close[i] - ln) * 100 / (hn - ln)
        ik = 2 * ik / 3 + rsv / 3
        id = 2 * id / 3 + ik / 3
        ij = 3 * ik - 2 * id
        k.push(ik)
        d.push(id)
        j.push(ij)
    }
    return {k, d, j}
}
function kdj(close, high, low, n = 5) {
    let len = close.length
    let k = []
    let d = []
    let j = []
    if (len === 0 || n <= 0) {
        return {k, d, j}
    }
    let ik = 50
    let id = 50
    let ij = 50
    let rsv = (close[0] - low[0]) * 100 / (high[0] - low[0])
    ik = 2 * ik / 3 + rsv / 3
    id = 2 * id / 3 + ik / 3
    ij = 3 * ik - 2 * id
    k.push(ik)
    d.push(id)
    j.push(ij)

    let ln = low[0]
    let hn = high[0]
    for (let i = 1; i < len; i++) {
        if (i < n) {
            if (ln > low[i]) {
                ln = low[i]
            }
            if (hn < high[i]) {
                hn = high[i]
            }
        } else {
            if (ln === low[i - n]) {
                ln = low[i]
                for (let j = 1; j < n; j++) {
                    if (low[i - j] < ln) {
                        ln = low[i - j]
                    }
                }
            } else {
                if (ln > low[i]) {
                    ln = low[i]
                }
            }

            if (hn === high[i - n]) {
                hn = high[i]
                for (let j = 1; j < n; j++) {
                    if (high[i - j] > hn) {
                        hn = high[i - j]
                    }
                }
            } else {
                if (hn < high[i]) {
                    hn = high[i]
                }
            }
        }
        rsv = (close[i] - ln) * 100 / (hn - ln)
        ik = 2 * ik / 3 + rsv / 3
        id = 2 * id / 3 + ik / 3
        ij = 3 * ik - 2 * id
        k.push(ik)
        d.push(id)
        j.push(ij)
    }
    return {k, d, j}
}
function kdj ( close , high , low , n = 5 ) { let len = close . length let k = [ ] let d = [ ] let j = [ ] if ( len === 0 || n <= 0 ) { return { k , d , j } } let ik = 50 let id = 50 let ij = 50 let rsv = ( close [ 0 ] - low [ 0 ] ) * 100 / ( high [ 0 ] - low [ 0 ] ) ik = 2 * ik / 3 + rsv / 3 id = 2 * id / 3 + ik / 3 ij = 3 * ik - 2 * id k . push ( ik ) d . push ( id ) j . push ( ij ) let ln = low [ 0 ] let hn = high [ 0 ] for ( let i = 1 ; i < len ; i ++ ) { if ( i < n ) { if ( ln > low [ i ] ) { ln = low [ i ] } if ( hn < high [ i ] ) { hn = high [ i ] } } else { if ( ln === low [ i - n ] ) { ln = low [ i ] for ( let j = 1 ; j < n ; j ++ ) { if ( low [ i - j ] < ln ) { ln = low [ i - j ] } } } else { if ( ln > low [ i ] ) { ln = low [ i ] } } if ( hn === high [ i - n ] ) { hn = high [ i ] for ( let j = 1 ; j < n ; j ++ ) { if ( high [ i - j ] > hn ) { hn = high [ i - j ] } } } else { if ( hn < high [ i ] ) { hn = high [ i ] } } } rsv = ( close [ i ] - ln ) * 100 / ( hn - ln ) ik = 2 * ik / 3 + rsv / 3 id = 2 * id / 3 + ik / 3 ij = 3 * ik - 2 * id k . push ( ik ) d . push ( id ) j . push ( ij ) } return { k , d , j } }
KDJ
close should have
KDJ close should have