calcCCI static method

void calcCCI(
  1. List<KLineEntity> dataList
)

Implementation

static void calcCCI(List<KLineEntity> dataList) {
  final size = dataList.length;
  final count = 14;
  for (int i = 0; i < size; i++) {
    final kline = dataList[i];
    final tp = (kline.high + kline.low + kline.close) / 3;
    final start = max(0, i - count + 1);
    var amount = 0.0;
    var len = 0;
    for (int n = start; n <= i; n++) {
      amount += (dataList[n].high + dataList[n].low + dataList[n].close) / 3;
      len++;
    }
    final ma = amount / len;
    amount = 0.0;
    for (int n = start; n <= i; n++) {
      amount +=
          (ma - (dataList[n].high + dataList[n].low + dataList[n].close) / 3)
              .abs();
    }
    final md = amount / len;
    kline.cci = ((tp - ma) / 0.015 / md);
    if (kline.cci!.isNaN) {
      kline.cci = 0.0;
    }
  }
}