What is the Commodity Channel Index (CCI)? Formula and example

On this page

Key takeaways

  • The CCI asks how unusual today's price is compared with its recent average, measured against how far prices have typically strayed from that average.
  • Zero means the price is at its average. Lambert scaled the index so that most readings stay between minus one hundred and plus one hundred; readings outside that band are the unusual ones.
  • Lambert read a rise above plus one hundred as the start of an uptrend, a momentum signal; many traders now read the same level as overbought, the opposite bet. The indicator does not settle which reading is right.
  • Despite its name, the CCI works on any asset with daily highs, lows and closes; nothing in it is specific to commodities.
  • MarketHeist's default rule is long while the CCI is above zero, which is close to holding while the price is above its twenty-day average.

Definition

The Commodity Channel Index (CCI), introduced by Donald Lambert in 1980, measures how far the typical price, the average of the high, low and close, sits from its own moving average, divided by the average absolute deviation over the same window and by the constant 0.015. Lambert chose the constant so that most readings fall between −100 and +100, and he treated a move beyond +100 as the start of a strong upward trend.

Also known as: CCI, commodity channel index, Lambert CCI, CCI 20, CCI +100 and -100, typical price, mean deviation.

How it works

The CCI starts from the typical price, the average of the day's high, low and close, which summarises where the day traded rather than only where it ended. It takes the 20-day simple moving average of the typical price, then measures how far today's typical price is from that average. To make the distance comparable across calm and volatile periods, it divides by the mean deviation: the average absolute distance of the last twenty typical prices from their average.

The last step is Lambert's constant. Dividing by 0.015 times the mean deviation scales the index so that, in the markets Lambert studied, most readings fell between −100 and +100. A reading of +100 therefore means the typical price is one and a half mean deviations above its average, and −100 the same distance below.

The CCI is like grading a test on a curve: the score says how far today's price is from the class average, in units of how spread out the class usually is.

Lambert designed it for commodity cycles and used it as a trend signal: buy when the CCI rises above +100 and exit when it falls back below, the reverse for short sales below −100. Later traders often read the same levels as overbought and oversold and trade the other way. The two readings make opposite bets on the same number, which is why a backtest has to pick one and test it.

Two choices separate the CCI from a z-score or Bollinger %B. It uses the typical price rather than the close, so intraday highs and lows count, and it divides by the mean absolute deviation rather than the standard deviation, which gives large one-off moves less weight. Its zero line is the moving average of the typical price, so a rule that is long above zero behaves much like the price above its 20-day average.

Formula

Commodity Channel Index (Lambert)
TPt=Ht+Lt+Ct3,At=1n∑j=0n−1TPt−j,MDt=1n∑j=0n−1|TPt−j−At|,CCIt=TPt−At0.015MDt
Hₜ, Lₜ, Cₜ
adjusted high, low and close on day t
TPₜ
typical price
n
window: 20 by default
j
days back from day t, from 0 to n − 1
Aₜ
simple moving average of the typical price
MDₜ
mean absolute deviation of the last n typical prices from Aₜ
0.015
Lambert's scaling constant

The deviations are measured from the current window's average Aₜ, so each day's mean deviation uses one centre for all n values. The CCI is undefined when the mean deviation is 0.

Worked example

SPY's daily bars from Oct 2006 to Sep 2026, about 20 years, with the 20-day CCI and three rules, each acted on with the standard one-bar delay, no trading costs and no interest on cash.

SPY's CCI had a median of 63.61 over the window, and on four days in five it sat between -127.10 and 147.72. Its latest reading was 10.14.

The default rule, long while the CCI was above zero, held SPY on 66.7% of days and completed 250 round trips, 12.5 a year. It grew 4.9% a year against 11.1% for holding SPY, with a worst decline of -37.1% against -55.2%.

Lambert's trend reading, long only while the CCI was above +100, was invested on 32.4% of days, in trades that lasted 4.6 days on average, and its growth rate over the window was 0.0% a year. The opposite bet, long only while the CCI was below −100, was invested on 14.5% of days and grew 3.4% a year, with a worst decline of -27.7%.

None of the three grew as fast as holding SPY over this window. Readings above +100 lasted only days at a time, so on daily SPY the trend reading caught short bursts rather than whole trends, and the oversold reading was invested exactly when SPY had just fallen hard, through the continuations as well as the rebounds.

Data through Sep 2026. Reproduce id 6ca1bd6f475dc655 (this guide, its lab setup and the data month).

Interactive lab

SPY's price with the days invested shaded, the CCI with its zero, +100 and −100 lines, and the results table for the zero-line rule, Lambert's +100 reading and the −100 reading against buy-and-hold. Change the period, the level, the direction, the cost or the fund.

SPY price with the days the base rule held itS&P 500, adjusted daily close, Oct 2006 to Sep 2026, log scale. Shaded: the 251 stretches the base rule held the fund (67% of 5030 days).$50$100$200$50020062011201620212026SPY adjusted closeHeld by the base rule
SPY on a log scale. Shaded: the days the base rule held the fund. Oct 2006 to Sep 2026.
CCI with the base rule's lineCCI on SPY, Oct 2006 to Sep 2026. The rule compares it with the fixed line 0.-400-300-200-1000100200200620112016202120260CCI
CCI and the line the base rule compares it with. Oct 2006 to Sep 2026.
Growth of $10,000: the setups against buy and holdS&P 500, Oct 2006 to Sep 2026, log scale. $10,000 grows to $26,158 (base), $10,016 (Lambert's trend reading: CCI above +100), $19,561 (Oversold reading: CCI below −100), $82,292 (buy and hold).$10k$20k$50k20062011201620212026Base ruleLambert's trend reading: CCI above +100Oversold reading: CCI below −100Buy and hold
Growth of $10,000 on a log scale, same days for every line. Oct 2006 to Sep 2026.
MeasureBaseLambert's trend reading: CCI above +100Oversold reading: CCI below −100Buy and hold
CAGR4.9%0.0%3.4%11.1%
Volatility (annualized)11.2%6.7%12.3%19.4%
Maximum drawdown-37.1%-40.3%-27.7%-55.2%
Sharpe ratio0.490.030.340.64
Sortino ratio0.670.040.50n/a
Growth of $10,000$26,158$10,016$19,561$82,292
Time in the market66.7%32.4%14.5%100.0%
Round trips250357198n/a
Round trips per year12.517.99.9n/a
Win rate39.6%41.7%74.2%n/a
Average win3.3%1.2%1.3%n/a
Average loss-1.4%-0.8%-2.3%n/a
Payoff ratio2.301.430.55n/a
Average days held13.44.63.7n/a
Expectancy per trade0.4%0.0%0.4%n/a
Profit factor, per day1.121.011.181.13
Profit factor, per trade1.511.021.63n/a
Indicator, last day10.13910.13910.139n/a
Indicator, 10th / 50th / 90th percentile-127.104 / 63.608 / 147.723-127.104 / 63.608 / 147.723-127.104 / 63.608 / 147.723n/a
Days the rule alone is long66.7%32.4%14.5%n/a

S&P 500, Oct 2006 to Sep 2026, 5030 trading days. Every setup is measured over the same days, with the indicator warmed up on earlier ones; cash earns 0. Base: CCI (period 20); long while the CCI is above 0; execution delay 1; cost 0 bps one way. Lambert's trend reading: CCI above +100: CCI (period 20); long while the CCI is above 100; execution delay 1; cost 0 bps one way. Oversold reading: CCI below −100: CCI (period 20); long while the CCI is below -100; execution delay 1; cost 0 bps one way.

Buy and hold, same daysValue
Largest one-day gain14.5% on 13 Oct 2008
Largest one-day loss-10.9% on 16 Mar 2020
CAGR without the 10 largest gains6.6%
CAGR without the 30 largest gains1.8%
CAGR without the 10 largest losses16.0%
CAGR without the 30 largest losses22.1%

The days replaced by 0 are the largest daily gains (or losses) of the window.

How MarketHeist computes it

Every choice an implementation has to make, as the code makes it today. The page is checked against the code each time it is built.

ChoiceHow it is computedIn the code
DataDaily bars (open, high, low, close, volume) of the fund as the MarketHeist data service serves them to the backtester: prices adjusted for splits and dividends, so a dividend counts as reinvested. They come from a snapshot taken each month and cut at the data month of this page, and are not rounded. The fund's own history, not an extension: a fund younger than the window is measured over the years it has.
WindowThe worked example and the lab measure the last 20 years of trading days, Oct 2006 to Sep 2026 (5030 days), ending at the data month of this page. Every setup, and buy and hold, is measured over exactly these days; an indicator is warmed up on the days before them, so changing a setting never moves the window, and a setting that needs more history than exists before the window is refused rather than measured over fewer days.
BacktestThe backtester's own engine, in the order it runs it: the indicator, the position rule (or entry and exit triggers) and the optional regime filter produce a position for every day of the fund's whole history; the position is then shifted forward by the execution delay and applied to each day's return over the window. Cash earns 0, there is no leverage, and a one-way cost in basis points is charged on the size of every change of position. Round trips are the closed entries of the trade log (a trade still open on the last day is not counted); the win rate is the share of them with a gain; the payoff ratio is the average win over the size of the average loss; expectancy is the average return per trade; the per-trade profit factor is the sum of the winning trades' returns over the size of the sum of the losing ones, while the per-day profit factor sums days.
Years and volatilityA year is 252 trading days, the engine's convention: trades per year is round trips over days divided by 252, the CAGR is the growth multiple to the power 252 over the days, and volatility is the sample standard deviation of the daily returns times the square root of 252.
Indicator statisticsThe indicator's main output over the window: its last value, its 10th, 50th and 90th percentile (linear interpolation between ranks), and the share of days the rule alone says long, before the delay and any regime filter. Every output of the indicator is also summarized by its median and the share of days below 0.
Buy and holdThe fund held every day of the window with dividends reinvested. The largest one-day gain and loss are the highest and lowest daily returns; the CAGR without the 10 or 30 largest gains (or losses) replaces those days' returns with 0 and recompounds.
Typical price(high + low + close) ÷ 3 on the adjusted daily bars; undefined if any of the three is missing.computepackages/shared/engine/indicators/cci.ts
AverageSimple moving average of the typical price over the period (default 20, range 5 to 200), the current bar included.smapackages/shared/engine/utils.ts
Mean deviationMean of |typical price − window mean| over the same window, dividing by n (not n − 1); the window mean is recomputed for each day.rollingMeanAbsDevpackages/shared/engine/utils.ts
Index(typical price − average) ÷ (0.015 × mean deviation); no value when the mean deviation is 0 or during the first period − 1 bars.computepackages/shared/engine/indicators/cci.ts
DefaultsPeriod 20; default rule long while the CCI is above 0.SPECpackages/shared/engine/indicators/cci.ts
Engine functionsThe functions the portfolio app and the MarketHeist MCP tools run, called here on the same monthly returns.computePositionpackages/shared/engine/run_basic.tsgeneratePositionpackages/shared/engine/positions.tsapplyRegimeFilterpackages/shared/engine/regime_filter.tsgenerateTriggeredPositionpackages/shared/engine/triggered_position.tsrunBacktestpackages/shared/engine/backtest.tsgetIndicatorpackages/shared/engine/indicators/registry.ts

Commodity Channel Index (CCI) compared with its neighbours

The CCI compared with Bollinger %B and other oscillators
IndicatorPrice usedScaled byUsual levels
CCITypical price (high, low, close)0.015 × mean absolute deviation±100
Bollinger %BCloseTwo standard deviations either side of the average0 and 1 (the bands)
Z-score of the closeCloseOne standard deviation±2
RSIClose-to-close changesAverage gain against average loss, 0 to 10030 and 70
Stochastic %KClose within the high-low rangeThe range itself, 0 to 10020 and 80

Limitations

  • The ±100 band is a scaling convention from Lambert's commodity data. On other assets and windows the share of readings beyond it varies, so the levels are not equally rare everywhere.
  • The same level supports opposite rules, trend and overbought. Picking one after seeing the results is a form of overfitting.
  • The example charges no trading costs. Rules that act on short excursions beyond ±100 trade often and hold briefly, which makes costs a large share of their result.
  • Adjusted highs and lows keep the typical price consistent across dividends, but values can differ slightly from platforms that use unadjusted prices.
  • One fund over one window that rose for most of its length; the same rules behave differently on assets that trend down or move sideways for years.

Frequently asked questions

What does a CCI above +100 mean?
The typical price is unusually far above its 20-day average, relative to how far it usually strays. Lambert read it as the start of a strong uptrend; many traders read it as overbought. The number itself only says the move was large for the recent past.
Why does the CCI use the constant 0.015?
Lambert chose it so that most readings would fall between −100 and +100 in the commodity markets he studied. It is a scaling factor: changing it would move every reading proportionally and change nothing about where the zero line is.
What is the difference between the CCI and Bollinger %B?
Both measure how far price is from a moving average relative to recent dispersion. The CCI uses the typical price and the mean absolute deviation; %B uses the close and the standard deviation and places the result between bands at 0 and 1.
Is the CCI only for commodities?
No. It was designed for commodity futures, but it needs only daily highs, lows and closes and is applied to stocks, funds and currencies alike.
Why is MarketHeist's default CCI rule long above zero?
Zero is the CCI's natural centre: above it, the typical price is above its 20-day average. It is a neutral starting point for a test, close to a short-term trend rule; the lab lets you switch to Lambert's +100 level or the −100 reading.

References

  1. Lambert, D. R. (1980) Commodity Channel Index: Tool for Trading Cyclic Trends. Commodities magazine (now Futures). The original description of the CCI and its 0.015 constant.
  2. Colby, R. W. (2003) The Encyclopedia of Technical Market Indicators. McGraw-Hill, second edition. Formula and common readings of the CCI.
  3. Murphy, J. J. (1999) Technical Analysis of the Financial Markets. New York Institute of Finance. Oscillators and their overbought and oversold readings.

Try it on your own holdings

Open the CCI in the backtester →

Or ask an assistant connected to the MarketHeist MCP server (https://marketheist.io/mcp), which computes the same figures:

Using MarketHeist.io, backtest the 20-day CCI on SPY daily bars with execution delay 1 three ways: long while CCI is above 0, long only while CCI is above 100, and long only while CCI is below -100. Compare time in the market, trades, CAGR and max drawdown with buy-and-hold.

Ask an AI assistant

The prompt opens in a new tab, already filled in. An assistant without the MarketHeist connector answers from its own knowledge, not from the figures on this page.

Historical simulation, not advice. Computed by the MarketHeist portfolio engine from monthly total returns, data through Sep 2026. Markdown version of this page: cci.md.