Skip to main content
BTC / USDT——ETH / USDT——SOL / USDT——BNB / USDT——XRP / USDT——DOGE / USDT——TON / USDT——AVAX / USDT——LINK / USDT——ADA / USDT——TRX / USDT——DOT / USDT——BTC / USDT——ETH / USDT——SOL / USDT——BNB / USDT——XRP / USDT——DOGE / USDT——TON / USDT——AVAX / USDT——LINK / USDT——ADA / USDT——TRX / USDT——DOT / USDT——
Prezzi

CCI (Commodity Channel Index)

Deviation-from-mean momentum with ±100 extremes — TradeStation and MetaStock code.

CCI measures how far price has strayed from its statistical mean, normalized by mean deviation. Readings above +100 flag unusually strong upside momentum (possible overbought), below −100 the reverse; zero-line crosses are used as trend triggers. Copy the version for your platform.

MQL4 · CCI.mq4
#property indicator_separate_window
#property indicator_buffers 1

input int CCIPeriod = 20;

double CCIBuffer[];

int OnInit() {
  SetIndexBuffer(0, CCIBuffer);
  IndicatorShortName("CCI");
  return 0;
}

int OnCalculate(const int rates_total, const int prev_calculated, const double &close[]) {
  for (int i = 0; i < rates_total; i++) {
    CCIBuffer[i] = iCCI(NULL, 0, CCIPeriod, PRICE_TYPICAL, i);
  }
  return rates_total;
}
MQL5 · CCI.mq5
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1

input int CCIPeriod = 20;

double CCIBuffer[];

int OnInit() {
  SetIndexBuffer(0, CCIBuffer, INDICATOR_DATA);
  IndicatorSetString(INDICATOR_SHORTNAME, "CCI");
  return INIT_SUCCEEDED;
}

int OnCalculate(const int rates_total, const int prev_calculated,
                const datetime &time[], const double &open[],
                const double &high[], const double &low[],
                const double &close[], const long &tick_volume[],
                const long &volume[], const int &spread[]) {
  for (int i = 0; i < rates_total; i++) {
    CCIBuffer[i] = iCCI(_Symbol, PERIOD_CURRENT, CCIPeriod, PRICE_TYPICAL);
  }
  return rates_total;
}
Pine Script
//@version=5
indicator("CCI")
length = input.int(20, "Length")
plot(ta.cci(close, length), "CCI", color=color.red)
EasyLanguage
inputs: Length(20);
Plot1(CCI(Length), "CCI");
MetaStock
CCI(20)

To use it inside dtcharts, paste any version into the Script Converter and it becomes a native indicator on your chart.