Skip to main content
BTC / USDTCRYPTO107,400+2.19%ETH / USDTCRYPTO3,840+2.13%SOL / USDTCRYPTO182.40−1.99%BNB / USDTCRYPTO652.30+0.66%XRP / USDTCRYPTO2.2150+1.61%DOGE / USDTCRYPTO0.3850−1.79%TON / USDTCRYPTO5.240+2.34%AVAX / USDTCRYPTO42.60−2.07%LINK / USDTCRYPTO22.40+2.28%ADA / USDTCRYPTO1.0520−1.68%TRX / USDTCRYPTO0.3300+0.92%DOT / USDTCRYPTO8.420+2.93%BTC / USDTCRYPTO107,400+2.19%ETH / USDTCRYPTO3,840+2.13%SOL / USDTCRYPTO182.40−1.99%BNB / USDTCRYPTO652.30+0.66%XRP / USDTCRYPTO2.2150+1.61%DOGE / USDTCRYPTO0.3850−1.79%TON / USDTCRYPTO5.240+2.34%AVAX / USDTCRYPTO42.60−2.07%LINK / USDTCRYPTO22.40+2.28%ADA / USDTCRYPTO1.0520−1.68%TRX / USDTCRYPTO0.3300+0.92%DOT / USDTCRYPTO8.420+2.93%
Pricing

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.