All free tools

Momentum indicator

CCI Calculator

Compute the Commodity Channel Index for one bar from the typical price, its moving average, and the mean deviation. What CCI captures, how far price sits from its statistical norm, is the key idea.

CCI
110.24
Above +100, a traditionally strong reading.

What the CCI is

The Commodity Channel Index, introduced by Donald Lambert in 1980, measures how far the current price has strayed from its average, scaled by how much it typically strays. Despite the name, it is applied to any market, not just commodities.

The calculation begins with the typical price of each bar, the average of the high, low, and close. It then takes a simple moving average of the typical price over the chosen period, by default 20, and the mean absolute deviation, the average distance of each typical price from that moving average. CCI is then (typical price − moving average) ÷ (0.015 × mean deviation). Lambert chose the 0.015 constant so that roughly 70 to 80 percent of values fall between −100 and +100, meaning readings outside that band mark price as unusually far from its recent average.

Why the CCI is used

CCI is used to identify when price has moved to an unusual extreme relative to its recent norm and to study momentum. Traders traditionally treat moves above +100 or below −100 as notable, and some watch the zero line and divergences between CCI and price.

The 20-period default and the ±100 levels are conventions rather than fixed rules, and are frequently adjusted. How you read the output is entirely up to you.

What are TradingView and Pine Script?

TradingView is one of the most widely used charting and market-analysis platforms, where traders and analysts study price movement across stocks, crypto, forex, and futures on interactive charts. Pine Script is TradingView's own lightweight programming language, created so anyone can build custom tools that run directly on those charts.

People use Pine Script to build four main kinds of tools. Indicators calculate and plot values on the chart, exactly like the calculation above, but recomputed automatically on every bar. Strategies add explicit entry and exit rules and can be backtested against historical data in TradingView's Strategy Tester to see how they would have behaved. Screeners scan many symbols at once for conditions you define. Alerts notify you the moment a condition you specified occurs, so you do not have to watch the screen.

The value is precision and automation. Instead of eyeballing a chart, you describe exactly what you want measured, visualized, or notified about, and TradingView runs it consistently across any market and timeframe. That is why traders, analysts, and developers write Pine Script: it turns a manual charting idea into a repeatable tool. These tools are for tracking, visualizing, and testing market ideas; they do not tell you what to trade, and that decision always remains yours.

Writing that code by hand means learning Pine Script's syntax, its type system, and the exact names of hundreds of built-in functions. It is a real programming language, and small mistakes stop a script from compiling in the Pine Editor.

Turn this into Pine Script

Here you get one CCI value. On a chart it recalculates every bar in its own pane with the ±100 guide lines. Pine Script provides it as ta.cci(close, 20), but the levels, coloring, and any signal logic around it still need to be written.

Pine Script v6
//@version=6
indicator("CCI", overlay=false)

cciValue = ta.cci(close, 20)

plot(cciValue, "CCI", color=color.blue)
hline(100, "Upper")
hline(-100, "Lower")

PineScripter is an AI built specifically for Pine Script. You describe what you want in plain English and it writes TradingView-ready v5 or v6 code. Because it is specialized on the Pine Script language and its exact function signatures, it tends to produce code that compiles far more reliably than general-purpose models like ChatGPT, which often invent functions that do not exist in Pine Script.

PineScripter is an AI developer tool that helps you write Pine Script code. It is not a financial advisor and will never offer financial, investment, or trading advice. Everything on this page, including the calculator and the explanations, is provided purely for educational and informational purposes. Any decision about how to interpret an indicator or trade a market is entirely your own. See our full disclaimer for more.