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.
#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;
}#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;
}//@version=5
indicator("CCI")
length = input.int(20, "Length")
plot(ta.cci(close, length), "CCI", color=color.red)inputs: Length(20);
Plot1(CCI(Length), "CCI");CCI(20)To use it inside dtcharts, paste any version into the Script Converter and it becomes a native indicator on your chart.