TradingView indicator guide
Commodity Channel Index on TradingView
The Commodity Channel Index (CCI) measures how far price is from its recent average relative to its usual dispersion. Values beyond +100 or -100 flag a large deviation. They can accompany a continuing trend, so an extreme reading alone is not a reversal signal.
Choose the rule before reading the level
Buying a break above +100 and selling the same break are different hypotheses. Below are separate continuation and reversal rules, a worked calculation and a configurable indicator you can inspect in TradingView.
CCI formula and a worked example
For a window of N bars, calculate the typical price of each bar, then their mean. Mean deviation uses each value's absolute distance from that same current-window mean, not its own historical moving average.
TP = (High + Low + Close) / 3 Mean = sum of the N typical prices / N MD = sum of |each TP - Mean| / N CCI = (current TP - Mean) / (0.015 × MD)
Illustrative three-bar calculation: typical prices are 98, 100 and 102. Their mean is 100; absolute distances are 2, 0 and 2, so MD is 4/3. The latest CCI is 2 / (0.015 × 4/3) = +100. Three bars make the arithmetic readable; this is not a recommended trading setting. If MD is zero, the formula has no defined value and should not be treated as a valid signal.
The 0.015 factor scales the oscillator. It does not make ±100 a probability band. CCI has no fixed upper or lower bound, and zero means the selected source equals its window average.
Formula reference: TradingView's CCI documentation.
Trend continuation versus mean reversion
A move above +100 can show buying strength. A return from an extreme can be used to investigate a reversal. Neither tells you where to place an order or when to accept a loss. The two long-only examples below are illustrative test specifications, not validated strategies or trade recommendations.
| Decision | Trend continuation | Mean reversion |
|---|---|---|
| Market filter | Close is above a rising 50-period EMA; define rising as EMA today above EMA five bars earlier. | Price is inside a range whose boundaries were recorded before the signal. Exclude closes below the recorded lower boundary. |
| Entry trigger | On a completed bar, CCI crosses from at or below +100 to above +100. Enter at the next bar open in the test. | After CCI closes below -100, wait for a completed bar to cross back above -100. Enter at the next bar open in the test. |
| Exit rule | Exit after a close below zero, or at a protective stop fixed at two entry-time ATR(14) units below the fill, whichever occurs first. | Take profit at the recorded range midpoint; place a stop below the lower boundary with a predefined buffer. Exit after ten bars if neither fills. |
| Failure condition | A brief price spike can satisfy both filters and reverse. A flat or changing trend can cause repeated losses. | A range can break into a downtrend. CCI recovering from an extreme does not mean price has recovered or will reach the midpoint. |
For the range example, record how boundaries and the stop buffer are selected before running the test. Skip an entry if the opening fill is already beyond the stop or profit target. Use one open position at a time, define sizing in advance, and include commission, slippage and gap fills. Drawing a range after seeing the reversal introduces hindsight.
In a strong downtrend, repeated readings below -100 can keep a reversal rule buying a falling market. In a choppy market, repeated crosses above +100 can keep a continuation rule buying moves that stall. A trend filter changes which trades qualify; it does not remove these failure modes.
Interpretation reference: Fidelity's CCI guide. The numerical rules in the table are examples created for this guide.
Add a CCI indicator to TradingView
Search for Commodity Channel Index in TradingView's Indicators menu for the built-in version. To inspect or change the calculation inputs, paste the example below into Pine Editor, save it and select Add to chart. It draws CCI in a separate pane and exposes length, source and threshold settings.
//@version=6
indicator("Commodity Channel Index", shorttitle="CCI", overlay=false)
length = input.int(20, "Length", minval=2)
source = input.source(hlc3, "Source")
threshold = input.float(100.0, "Threshold", minval=1.0)
cci = ta.cci(source, length)
plot(cci, "CCI", color=color.blue, linewidth=2)
upper = hline(threshold, "Upper threshold", color=color.gray)
hline(0, "Zero", color=color.new(color.gray, 50))
lower = hline(-threshold, "Lower threshold", color=color.gray)
fill(upper, lower, color=color.new(color.blue, 92))This script starts with HLC3, length 20 and ±100 reference levels. Match the Source setting when comparing it with another indicator; close and HLC3 are different inputs. The threshold input moves the reference lines without changing the CCI calculation. No orders, entry markers or alerts are included.
Wait for the signal you actually intend to test
High, low and close can change while a bar is open, so this CCI line can move across a threshold and back before the close. If you add signals based on completed bars, require bar-close confirmation and use an alert frequency consistent with that rule. You give up an earlier intrabar signal in exchange for knowing the final value. Higher-timeframe inputs need their own confirmation handling.
Compare settings without selecting one lucky result
Use a small, declared experiment. For example, compare lengths 14, 20 and 30 with thresholds 100, 150 and 200: nine combinations. These are illustrative candidates, not recommended settings. Keep the price source, entry logic, sizing, exits, fees and slippage unchanged so you can attribute differences to the inputs being tested.
- Choose the symbol, session, timeframe and development dates before comparing results.
- Review trade count, drawdown and average trade after costs alongside total return. A handful of trades leaves substantial uncertainty.
- Check whether neighboring settings behave similarly. An isolated profit peak can disappear after a small parameter change.
- Freeze the rules and evaluate later dates that were not used to select the settings. Retuning on that period turns it into more development data.
A CCI indicator alone cannot produce strategy results. Convert the chosen hypothesis into explicit orders first. Pineify's Strategy Optimizer can compare numeric input ranges for a TradingView strategy. Use the results to examine parameter sensitivity; no parameter search proves that a rule will work in future markets.
Turn a defined CCI rule into a script
Pineify's AI Coding Agent can help write a custom indicator or strategy from your rules. Specify the threshold, the trend filter, bar-close behavior and exits. Review the generated code and its TradingView behavior before evaluating performance.
Prefer configuring indicators visually? The Visual Editor includes CCI with source and length inputs. Use it to assemble supported conditions; ask the Coding Agent for custom logic beyond that workflow.
Build a custom CCI scriptCCI questions
Sources and scope
- TradingView: Commodity Channel Index calculation and inputs
- Fidelity: interpreting CCI trend and reversal signals
- TradingView: repainting and confirmation on realtime bars
Sources checked October 16, 2026. Examples explain indicator mechanics and test design; they are not live signals or measured trading results.
Educational information, not investment advice. Trading can result in losses. Historical tests and syntax validation do not guarantee profitable execution.
Browse the TradingView indicators guide or continue with the EMA indicator for a trend filter or the Pine Script cheatsheet for syntax reference.