stratester.com

Indicators · condition block

CCI (Commodity Channel Index)

The CCI block measures how far the typical price has moved from its average, scaled by its typical deviation. Readings beyond +100 or −100 are traditionally treated as unusually strong or weak.

How the engine evaluates it

Typical price is (high + low + close) / 3. The engine averages it over N candles and computes the mean absolute deviation from that average.

CCI = (typical price − average) / (0.015 × mean deviation). If the deviation is zero, CCI is 0. The block compares CCI strictly with your level.

Formula
TP = (high + low + close) / 3
CCI = (TP − SMA(TP, N)) / (0.015 × mean |TP − SMA(TP, N)|)

Botscript syntax

In the Lab you pick this block from the Indicators group and fill in its fields. In the code view the same condition is written like this:

cci(20) < -100
cci(20) > 100

Settings

SettingValuesDefaultNotes
Comparison<, ><—
Level−10,000 – 10,000−100±100 is Lambert's original threshold.
Length2 – 5,00020—
Timeframethe run's candles, or 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d, 1wthe run's candlesOptional. At least the run's candle size and a whole multiple of it.

On a higher timeframe

Add a timeframe at the end to read CCI from bigger candles than the run uses, for example cci(20) < -100 on 4h. The engine builds those candles from the run's own candles (UTC, weeks start on Monday) and evaluates the block only on candles that have closed, so there is no look-ahead. Lengths and lookbacks count the bigger candles.

CCI is a state on a higher timeframe: the result from the last completed bigger candle holds on every run candle until the next one closes.

The timeframe must be at least the run's candle size and a whole multiple of it; otherwise the run stops with an error and is not charged. Multi-timeframe conditions covers the details, including warm-up.

How traders use it

  • Oversold entries: cci(20) < -100.
  • Momentum: cci(20) > 100 to join strong moves.
  • Exits: cci(20) > 100 with holding after a mean-reversion entry.

Example bot

botscript
bot "CCI Reversal"

when cci(20) < -150
then buy 50%

when cci(20) > 100
then sell 100%
  • Buys half the cash on a deep CCI reading.
  • Sells when CCI swings above +100.

Pitfalls

  • CCI is unbounded: extreme moves produce readings far beyond ±100.
  • Like other oscillators it can stay extreme in trends.

CCI: frequently asked questions

Why the 0.015 constant?

Donald Lambert chose it so that most readings fall between −100 and +100.

Can CCI go beyond 100?

Yes, it has no fixed range. Bitcoin regularly prints readings beyond ±200.

Which price does it use?

The typical price: the average of high, low and close.

Is the comparison strict?

Yes: < -100 needs a value below −100.

Simulated results are hypothetical. They include only the fee and slippage you set on the bot, not every real-world cost or market condition, and past performance does not guarantee future results. Nothing here is financial advice.