Indicator · Pine Script v6 · Own pane

Commodity Channel Index

by eddiebelaval· code credited to Tiagorocha1989

This indicator calculates and plots the Commodity Channel Index (CCI) alongside a configurable moving average in a separate pane.

View on GitHub

GitHub stars7on the repository
Pine versionv6current
Lines of code50
Settings3inputs
LicenceNone statedfile: MPL-2.0
Last update3 months ago24 Jul 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

50 lines of Pine Script v6 from pinescript/momentum/commodity-channel-index-cci.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

commodity-channel-index-cci.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Tiagorocha1989
//                              ████████╗ ████████╗  ████████╗  ███████╗   ██████╗        ██████╗   ██████╗   ██████╗ ██╗   ██╗ ████████╗
//                              ╚══██╔══╝ ╚══██╔══╝  ██╔═══██║  ██╔════╝  ██╔═══██╗       ██╔══██╗ ██╔═══██╗ ██╔════╝ ██║   ██║ ██╔═══██║
//                                 ██║       ██║     ████████║  ██║ ███║  ██║   ██║       ██████╔╝ ██║   ██║ ██║      ████████║ ████████║
//                                 ██║       ██║     ██╔═══██║  ██║  ██║  ██║   ██║       ██╔══██╗ ██║   ██║ ██║      ██║   ██║ ██╔═══██║
//                                 ██║    ████████╗  ██║   ██║  ███████║  ╚██████╔╝       ██║  ██║ ╚██████╔╝ ╚██████╗ ██║   ██║ ██║   ██║
//@version=6
indicator("Commodity Channel Index", "CCI →",false)
//╔════════════════════════╗
//║ Choose Moving Averages ║
//╚════════════════════════╝
ma(source, length, type) =>
     type == "EMA" ? ta.ema(source, length) :
     type == "SMA" ? ta.sma(source, length) :
     type == "SMMA / RMA" ? ta.rma(source, length) :
     type == "WMA" ? ta.wma(source, length) :
     type == "VWMA" ? ta.vwma(source, length) :
     type == "RMA" ? ta.rma(source, length) :
     type == "HMA" ? ta.hma(source, length) :
     na
//╔════════════════════════╗
//║     INPUT SETTINGS     ║
//╚════════════════════════╝
Length_CCI =    input.int(55, title = "CCI", group="SETTING")
Length_MA =     input.int(30, title = "MA", group="SETTING", inline = "MA")
Source_MA =     input.string("EMA", "", group="SETTING", inline = "MA", options=["EMA", "SMA", "SMMA / RMA", "WMA", "VWMA", "RMA", "HMA"],tooltip = "Moving Averages")
//╔════════════════════════╗
//║      Calculation       ║
//╚════════════════════════╝
CCI =       ta.cci(close,Length_CCI)
CCI_MA =    ma(CCI, Length_MA, Source_MA)
//╔════════════════════════╗
//║          Plot          ║
//╚════════════════════════╝
midLinePlot = plot(50, color = color.new(color.white,50))
Plot_CCI = plot(CCI, color = CCI > 50 ? color.new(#008000, 50):color.new(#FF0000, 50), linewidth = 3)
fill(Plot_CCI, midLinePlot, 200, 0, top_color = color.new(#008000, 50),    bottom_color = color.new(#008000, 100), title = "Overbought Gradient Fill")
fill(Plot_CCI, midLinePlot, 0, -100, top_color = color.new(#FF0000, 100), bottom_color = color.new(#FF0000, 50),    title = "Oversold Gradient Fill")
plot(CCI_MA, color = color.yellow)
isBull = CCI > 50
//╔════════════════════════╗
//║          VIEW          ║
//╚════════════════════════╝
var table Table_CCI = table.new(position.middle_right, 1, 1, border_width = 1)
if barstate.islast
    table.cell(Table_CCI, 0, 0, 
         text = isBull ? "⬆️ Bullish" : "⬇️ Bearish", 
         text_color = isBull ? #008000 : #FF0000,
         text_size = size.huge)

Overview

The CCI line dynamically changes color based on whether its value is above or below a threshold level of 50, accented by gradient fills toward the midline. User settings allow adjustment of the CCI calculation length, as well as the length and type of smoothing moving average, including EMA, SMA, RMA, WMA, VWMA, and HMA.

Details

Published by

eddiebelaval on GitHub

Code credit

Tiagorocha1989, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
CCIint55Length_CCI
MAint30Length_MA
Source_MAstringEMASource_MA
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

948 stars

The Derivative Oscillator calculates a double-exponentially smoothed Relative Strength Index (RSI) and subtracts its Simple Moving Average (SMA) to form the main oscillator line. A secondary signal line is plotted using an SMA of the main oscillator values. Th

Indicator v4 Oscillators & momentumMoving averages
Updated 10 days ago · GPL-3.0 GitHub repository of Derivative Oscillator

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop

MACD

by Alorse
330 stars

This indicator calculates and plots the standard Moving Average Convergence Divergence oscillator in a separate pane. It computes the difference between a fast and slow moving average, derives a signal line through smoothing, and plots a histogram representing

Indicator v4 Oscillators & momentumMoving averages
Updated 2 months ago · None stated GitHub repository of MACD

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V
218 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers