全職奶爸

CCI Indicator: Formula, TradingView Settings and ±100 Signals

CCI: formula, source selection and TradingView settings

The CCI indicator compares a selected price with its recent average, then scales that difference by the window's mean absolute deviation. Readings above +100 or below −100 describe a relatively large deviation. They can accompany trend continuation as well as a potential return toward the average.

That is why selling every move above +100 can put you against a rising market repeatedly. The threshold tells you something about the relationship between price and its recent history. It does not tell you that the next candle must reverse.

The worked examples below separate three choices that can otherwise get mixed together: the price source, the CCI lookback, and an optional average drawn over the CCI line. The calculations use hypothetical bars so you can reproduce every number. For the classical TradingView setup, explicitly select Length 20 and Source HLC3.

What does the Commodity Channel Index measure?

CCI stands for Commodity Channel Index. Donald Lambert introduced it in 1980. The classical calculation uses typical price, meaning high plus low plus close divided by three, and measures its distance from a simple moving average of that same price series.

A positive reading means the current selected price is above its current-window average when the denominator is positive. A negative reading means it is below. A reading near zero means the two are close; it does not prove that the wider market has no trend.

The denominator matters as much as the distance. A move fifty points away from an average can look more extreme relative to a quiet recent window than to a window with much larger deviations. CCI is a normalized comparison, rather than a measurement of a fixed number of index points.

The scale is not confined to −100 and +100, or to RSI's familiar 0–100 display range. Values can extend beyond +200 or below −200. Those observations still describe the inputs and window you selected; a value of 200 is not a 200-point target or a probability of reversal.

CCI formula: use one mean for the entire window

Choose a source series x and a lookback N. The current window includes the latest observation and the preceding N−1 observations. First calculate one simple average of those N prices. Then compare every price in that window with that same average.

Mean = sum of the N source prices ÷ N.
Mean deviation = sum of |each source price − that mean| ÷ N.
CCI = (latest source price − mean) ÷ (0.015 × mean deviation).

The absolute-value signs keep positive and negative deviations from cancelling. Without them, the signed deviations around the same arithmetic mean sum to zero. The resulting zero would not be the intended denominator.

The 0.015 constant scales the ratio. It does not establish a guaranteed percentage of observations that must stay between the two reference levels in every market. The distribution you actually see depends on the selected source, window and data.

The StockCharts CCI calculation specifies that each observation is compared with the most recent window's average. Taking an average of residuals from several different historical averages produces a different calculation, even if every intermediate number is labelled “deviation.”

A four-bar CCI example you can reproduce

Use four hypothetical bars to keep the arithmetic short. This small example explains the formula; it is not the twenty-period setup or a record of trading performance. HLC3 is calculated separately for each bar from its high, low and close.

BarHighLowCloseHLC3
1100969898
210298100100
310395102100
4104100102102

The four HLC3 values are 98, 100, 100 and 102. Their mean is 100. The absolute deviations from that one mean are 2, 0, 0 and 2. Their sum is 4, so the mean deviation is 4 ÷ 4 = 1.

The latest HLC3 is 102. Its distance from the mean is 2, giving CCI = 2 ÷ (0.015 × 1) = 133.33, rounded to two decimals. This result is above +100 even though the last closing price did not change from the preceding bar.

Retain the denominator while checking a spreadsheet. Writing only the latest deviation and the final CCI hides the point where many calculation differences arise. A useful verification row includes the window's prices, current mean, absolute deviations, their average and the final ratio.

For a full twenty-period calculation, use twenty source observations for both the mean and the mean deviation. An incomplete opening window should not quietly be compared with a fully initialized twenty-period indicator. Also check whether the platform returns a blank, zero or another display value when every source price is equal and mean deviation is zero; the raw ratio is undefined in that case.

Mean deviation is different from standard deviation

For the HLC3 sample above, mean absolute deviation is 1. The population standard deviation is approximately 1.4142 because it averages squared deviations and then takes a square root. Substituting that second measure changes the denominator.

Using standard deviation would give 2 ÷ (0.015 × 1.4142), or approximately 94.28. The proper mean-deviation calculation gives 133.33. The substitution places the result on a different side of +100, so this is more than a cosmetic rounding difference.

Mean deviation and standard deviation differHypothetical HLC3prices98,100,100,102;mean100,currentdeviation2. CorrectMAD1givesCCI133.33. SubstitutingpopulationSD1.4142gives94.28andadifferentthresholdclassification.Mean deviation and standard deviation differHYPOTHETICAL · N = 4 · HLC3: 98, 100, 100, 102Mean 100 · Mean absolute deviation 1Correct CCI = 2 ÷ (0.015 × 1) = 133.33Population standard deviation = 1.4142Substitution gives 94.28 → a different calculationUse mean absolute deviation in the CCI denominator.

The Bollinger Bands guide explains a standard-deviation calculation around an average. Similar language about distance from a mean does not make its denominator interchangeable with CCI's mean absolute deviation.

Another error is to subtract a different rolling average from each historical price, then average those residual magnitudes. For example, the sequence 90, 92, 94, 98, 100, 100, 102 has a final four-price window of 98, 100, 100, 102. Its correct mean deviation remains 1. Averaging the latest four residuals from their own historical four-bar means instead produces 3.125 and a different result of 42.67.

Use a single current-window mean throughout each CCI calculation. On the next bar, a new window gets a new mean and a newly calculated set of deviations. This makes the definition reproducible without turning it into a chain of differently centered residuals.

Close and HLC3 can change the same chart's CCI signal

Now keep every hypothetical bar in the table unchanged and select Close instead of HLC3. The source series becomes 98, 100, 102 and 102. Its mean is 100.5. The absolute deviations are 2.5, 0.5, 1.5 and 1.5, giving a mean deviation of 1.5.

The latest distance is 102 − 100.5 = 1.5. The result is CCI = 1.5 ÷ (0.015 × 1.5) = 66.67. The HLC3 version is above +100 while the Close version is below it. Both follow the stated formula; their inputs differ.

Same OHLC bars, different CCI sourcesHypothetical fourOHLCbars keptunchanged. HLC398,100,100,102hasmean100,MAD1,CCI133.33. Close98,100,102,102hasmean100.5,MAD1.5,CCI66.67. The sourcechoicechangeswhetherthevalueexceeds100.Same OHLC bars, different CCI sourcesHYPOTHETICAL · N = 4 · Every OHLC bar stays unchangedHLC3: 98, 100, 100, 102Mean 100 · MAD 1 → CCI 133.33 (above +100)Close: 98, 100, 102, 102Mean 100.5 · MAD 1.5 → CCI 66.67 (below +100)Record the source as well as the length before comparing signals.

Changing the source changes the whole series of observations, not just the latest numerator. In this example, the third bar's HLC3 is 100 while its close is 102. That difference changes the window's mean and deviation as well as the final ratio.

A signal description should therefore include the source alongside the length. “CCI 20 crossed +100” leaves a meaningful choice unresolved. Record whether you used Close, HLC3 or another source before comparing a chart, replay and spreadsheet.

Even an unchanged latest close can accompany a changing CCI. If another close of 102 follows the Close-based sample, the new four-price window becomes 100, 102, 102, 102. Its mean is 101.5 and mean deviation is 0.75, so CCI falls to 44.44. The old observation leaving the window changed the calculation while the newest close repeated.

How to add and configure CCI in TradingView

Open Indicators, search for Commodity Channel Index, and choose the built-in indicator. Community scripts can add alerts, alternative sources, smoothing or trading rules under similar names. The TradingView indicators guide explains how to distinguish a calculation from a strategy and give each tool a clear role.

Open the indicator's settings beside its name and select Inputs. Set the main Length to 20. For the classical typical-price version, explicitly select Source HLC3, the high-low-close average. Select Close if that is the version your trading rule specifies, and keep that selection in the record.

TradingView CCI Inputs with main Length 20, a Source selector, separate smoothing controls and Timeframe Chart
The main CCI Length and the optional smoothing Length control different calculations. Open the settings image at full size.

Use Timeframe Chart to calculate on the chart's bars. Twenty five-minute bars represent one hundred minutes of bar duration when they are consecutive. Session boundaries and missing observations can change the elapsed span, so keep the session and feed with the interval.

If the calculation timeframe is higher than the chart timeframe, review Wait for timeframe closes. An hourly value still developing during a five-minute candle is different from the hourly reading confirmed at the end of that hour. A test must use the value that existed at the decision time.

In Style, make the base CCI line distinct from any additional average. Keep the 0, +100 and −100 references readable. A crossing by the auxiliary average is a different event from a crossing by CCI itself.

The two Length fields do different jobs

The main Length determines how many source prices enter the CCI mean and mean deviation. The Smoothing section adds an average of the calculated indicator as another plotted line. Its Type and Length do not replace the main CCI window.

The TradingView smoothing explanation describes this separate plot. Selecting Type None removes the extra moving average. The base CCI still uses its own simple mean and mean-deviation calculation.

For an uncluttered learning setup, use Type None and follow the base CCI line. If your rule uses an auxiliary average, record its type and length separately, such as SMA 14 over CCI 20. A crossover of those two series needs its own definition and timing.

BB StdDev belongs to the optional SMA + Bollinger Bands smoothing choice. It controls the additional bands around that smoothing average. It does not turn CCI's mean deviation into standard deviation or replace the 0.015 scaling constant in the base formula.

Crossing +100 and returning below +100 are different events

A move from CCI 80 to 120 is an outward crossing of +100. A later move from 140 to 90 is a return below it. A trend-following rule and a mean-reversion rule can deliberately study those opposite events. Combining them into “sell overbought” hides the actual trigger.

For a hypothetical continuation experiment, first define a price breakout or pullback setup. Then ask whether a completed CCI reading above +100 adds a useful filter. Decide whether the rule wants the first crossing or simply a value remaining above the threshold; those choices produce different eligible bars.

For a range-based reversal experiment, identify the range and its boundaries before the signal. A CCI return below +100 near a previously defined upper boundary can be one condition to investigate. It still needs an executable entry, an invalidation and an exit. The boundary should not be moved after the losing candle appears.

The negative side mirrors the distinction. Dropping through −100 can describe strengthening negative deviation, while recovering above −100 is a separate return event. Neither guarantees the next price direction. Count false starts and continued moves against the proposed reversal as part of the test.

CCI divergence needs corresponding, confirmed pivots

Regular bullish divergence pairs a lower price low with a higher CCI low. Regular bearish divergence pairs a higher price high with a lower CCI high. Compare pivots from corresponding moves rather than selecting whichever two indicator turns make the desired pattern.

Divergence says that the later price extreme did not produce the same normalized indicator extreme. The window's average and mean deviation may both have changed. It does not by itself explain why buyers or sellers acted, or supply the exact candle on which the trend will reverse.

If your pivot rule requires bars to the right of a potential high or low, the pivot is confirmed only after those later bars exist. A historical marker drawn back on the original pivot candle must not be treated as an entry available on that earlier candle.

Choose the confirmation and failure rules before measuring results. A price break beyond a named swing, a CCI zero-line crossing and a return through an extreme threshold are different conditions with different delays. Strong trends can produce repeated divergences before turning, and some never produce the reversal a trader expected.

CCI, RSI and ADX answer different questions

The RSI indicator guide explains the balance of smoothed upward and downward price changes on a 0–100 scale. CCI instead measures a selected price's deviation from its current-window average relative to mean deviation. Their threshold numbers and calculation lengths are not interchangeable.

The ADX and DMI guide separates directional dominance from smoothed trend strength. ADX discards the sign of the directional difference, so it can rise during either a rally or a selloff. A positive CCI, by contrast, locates the selected price above its own average when its denominator is positive.

Assign each indicator a distinct job before combining them. Several transformations of the same price history do not create independent guarantees. An extra oscillator deserves a place only if a complete comparison shows how its condition contributes to the intended rule.

Choose CCI day-trading settings with a complete test

Length 20 provides a clear baseline to record. A shorter lookback changes both the average and the deviation used for normalization. A longer lookback changes both too. The number of threshold crossings in a particular sample cannot be established from the length alone.

Compare a small, declared set of alternatives while holding source, instrument, session, entry, exit and costs constant. Then evaluate the selected rule on separate observations. Selecting a period because it fits one attractive historical cycle does not establish that it is optimal for later trades.

A one-minute and a five-minute CCI use different bar sequences even when both lengths are twenty. Record standard or alternative candle construction, the dated futures contract where applicable, and any session filter. A continuous contract and a dated contract can also supply different historical inputs.

For each potential setup, save the base CCI value, source, length, calculation timeframe and confirmation time. Include rejected signals and missed fills. Evaluate net expectancy, drawdown, losing streaks and trade count alongside win rate so a cleaner-looking subset does not hide the opportunities it removed.

Use price invalidation to determine the trade risk

CCI does not provide a price-distance stop. A reading of 150 does not mean a stop should be 150 points away, nor does a larger reading permit a larger loss allowance. Define where the price setup fails, then measure the distance from the intended entry to that level.

The position sizing calculator guide converts a stop distance, value per unit and cost assumptions into quantity within a chosen money-risk budget. Use the executable, tick-valid distance and allow for adverse execution. If minimum quantity exceeds the budget, skipping is a meaningful result.

For a prop firm evaluation, compare that planned exposure with the applicable account rules and remaining allowance. Repeated failed attempts can consume the available room even when every entry satisfies its CCI condition. Indicator agreement does not enlarge a loss limit or guarantee a protective stop's fill.

Compare HDP discounts

Lucid 30% · Tradeify 30% · TPT 50%.

See current offers ↗

Eligible partner plans only.

CCI indicator FAQ

What does CCI mean in trading?

CCI means Commodity Channel Index. It compares a selected price with its recent simple average and scales the difference by the same window's mean absolute deviation.

What is the CCI indicator formula?

CCI equals the latest source price minus the window's mean, divided by 0.015 times mean deviation. Mean deviation averages the absolute distances of every window observation from that one current mean.

Does CCI above +100 mean I should sell?

No. It can accompany a continuing upward move. A crossing above +100 and a later return below +100 are different events; define the price context, entry and invalidation before testing either.

Does CCI below −100 mean I should buy?

No. Negative deviation can persist during a downtrend. A recovery above −100 is a separate condition, and a reversal rule still needs price context and an executable risk plan.

Is CCI limited to −100 and +100?

No. Those are common reference levels rather than the indicator's fixed limits. Readings can extend beyond +200 or below −200 and do not represent probabilities or price targets.

What settings should I use to reproduce the classical calculation?

Use the built-in Commodity Channel Index, set the main Length to 20, and explicitly select HLC3 as Source. Record the chart and calculation timeframes and any confirmation setting.

Does Source Close give the same CCI as HLC3?

It can give a different value because it changes the entire input series. In the four-bar example, the same OHLC bars produce CCI 66.67 from Close and 133.33 from HLC3.

Is mean deviation the same as standard deviation?

No. Mean deviation averages absolute distances from the current-window mean. Standard deviation uses squared distances and a square root. Substituting one for the other changes CCI.

Why are there two Length fields in TradingView CCI?

The main Length controls the CCI source-price window. The Smoothing Length controls an additional moving average of the calculated indicator. They affect different series.

What does Smoothing Type None do?

It removes the auxiliary moving-average plot. The base CCI continues using its own simple mean and mean-deviation calculation; None does not remove those internal calculations.

What are the best CCI settings for a five-minute chart?

There is no universal optimum. Record a baseline such as Length 20 with an explicit source, compare a small set of alternatives under fixed trading rules and costs, and use separate validation observations.

Is CCI better than RSI?

They measure different features. CCI normalizes deviation from a price average; RSI transforms the balance of smoothed gains and losses. Compare their contribution to a defined rule rather than ranking them universally.

What is bullish or bearish CCI divergence?

Bullish divergence pairs a lower price low with a higher CCI low. Bearish divergence pairs a higher price high with a lower CCI high. Use corresponding confirmed pivots and allow for their confirmation delay.

Can CCI change before the candle closes?

Yes. A developing source price can change the window's mean, deviation and CCI. A higher calculation timeframe has its own confirmation timing. Use information available at the rule's specified decision time.