let calculateMA = (dayCount, data) => {
    let result = [];
    for (let i = 0, len = data.length; i < len; i++) {
        if (i < dayCount) {
            result.push('-');
            continue;
        }
        let sum = 0;
        for (let j = 0; j < dayCount; j++) {
            sum += data[i - j].close;
        }
        result.push(+(sum / dayCount).toFixed(3));
    }
    return result;
}



let calculateTP = (i, data) => {
    return (data[i].close + data[i].high + data[i].low) / 3;
}

// data: 开 收 低 高 成
let calculateCCI = (dayCount, data) => {
    let result = [];
    let sma = calculateMA(dayCount, data);
    for (let i = 0, len = data.length; i < len; i++) {
        if (i < dayCount) {
            result.push('-');
            continue;
        }
        let tp = calculateTP(i, data);
        let ma = sma[i], md = 0;
        for (let j = i - dayCount + 1; j <= i; j++) {
            md += Math.abs(calculateTP(j, data) - ma);
        }
        md /= dayCount;
        result.push(+((tp - ma)/md/0.015).toFixed(3));
    }
    return result;
}