Indicator · Pine Script v4 · Own pane

CCI DC

by be-thomas

This indicator plots the Commodity Channel Index of close in a separate pane and surrounds it with a Donchian channel whose lookback length changes with volatility.

View on GitHub

GitHub stars65on the repository
Pine versionv4older, still runs
Lines of code63
Settings3inputs
LicenceGPL-3.0
Last update4 days ago24 Oct 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

63 lines of Pine Script v4 from examples/v4/tradingview-docs/v4-essential-colors-07.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

v4-essential-colors-07.pine
//@version=4
study("CCI DC", precision = 6)
var color C_GOLD   = #CCCC00ff
var color C_VIOLET = #AA00FFff
int i_p = input(20, "Length", minval = 5)
color i_c_bull = input(C_GOLD,   "Bull")
color i_c_bear = input(C_VIOLET, "Bear")

// ————— Function clamps `_val_` between `_min` and `_max`.
f_clamp(_val, _min, _max) =>
    _return = max(_min, min(_max, _val))

// ————— Volatility expressed as 0-100 value.
float v = atr(i_p / 5) / atr(i_p * 5)
float vPct = percentrank(v, i_p * 5)

// ————— Calculate dynamic lookback for DC. It increases/decreases on low/high volatility.
bool highVolatility = vPct > 50
var int lookBackMin = i_p * 2
var int lookBackMax = i_p * 10
var float lookBack = avg(lookBackMin, lookBackMax)
lookBack += highVolatility ? -2 : 2
lookBack := f_clamp(lookBack, lookBackMin, lookBackMax)

// ————— Dynamic lookback length Donchian channel of signal.
float signal = cci(close, i_p)
// `lookBack` is a float; need to cast it to int to be used a length.
float hiTop  = highest(signal, int(lookBack))
float loBot  = lowest( signal, int(lookBack))
// Get margin of 25% of the DC height to build high and low bands.
float margin = (hiTop - loBot) / 4
float hiBot  = hiTop - margin
float loTop  = loBot + margin
// Center of DC.
float center = avg(hiTop, loBot)

// ————— Create colors.
color c_signal = color.from_gradient(signal, -200, 200, C_VIOLET, C_GOLD)
// Bands: Calculate transparencies so the longer since the hi/lo has changed, 
//        the darker the color becomes. Cap highest transparency to 90.
float hiTransp = f_clamp(100 - (100 * max(1, nz(barssince(change(hiTop)) + 1)) / 255), 60, 90)
float loTransp = f_clamp(100 - (100 * max(1, nz(barssince(change(loBot)) + 1)) / 255), 60, 90)
color c_hi = color.new(i_c_bull, hiTransp)
color c_lo = color.new(i_c_bear, loTransp)
// Background: Rescale the 0-100 range of `vPct` to 0-25 to create 75-100 transparencies.
color c_bg = color.new(color.gray, 100 - (vPct / 4))

// ————— Plots
// Invisible lines for band fills.
p_hiTop  = plot(hiTop, color = na)
p_hiBot  = plot(hiBot, color = na)
p_loTop  = plot(loTop, color = na)
p_loBot  = plot(loBot, color = na)
// Plot signal and centerline.
p_signal = plot(signal, "CCI", c_signal, 2)
plot(center, "Centerline", color.silver, 1)

// Fill the bands.
fill(p_hiTop, p_hiBot, c_hi)
fill(p_loTop, p_loBot, c_lo)

// ————— Background.
bgcolor(c_bg)

Overview

Short-term ATR relative to a longer ATR is ranked from 0 to 100; high volatility shortens the lookback and low volatility lengthens it, within limits set by the length input. It draws the CCI line, a centerline, inner and outer channel bands, and a gray background that darkens as volatility rank rises. Length and bull and bear colors are the main settings. It is not a strategy and has no entry or exit rules.

Details

Published by

be-thomas on GitHub

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

Category

Oscillators & momentum, Volatility & bands

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.

Topics

algorithmic-tradingbacktestingcompilerfintechjavascriptpinescripttechnical-analysistradingview

Settings

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

SettingTypeDefaultVariable
Lengthint20i_p
BullinputC_GOLDi_c_bull
BearinputC_VIOLETi_c_bear
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

TTM Squeeze

by Alorse
330 stars

This indicator plots a TTM Squeeze momentum oscillator in a separate pane. It compares a Bollinger Band offset to a Keltner Channel offset and marks the zero line white when the difference is non-negative and black when the bands are inside the channel. A line

Indicator v5 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of TTM Squeeze

Function - Logistic Equation

by ricardosantos79
261 stars

Calculates dynamic modeling values by applying a mathematical logistic differential equation to price change over a specified lookback length. It measures price momentum relative to the recent high-low price range. The script plots positive and negative logist

Indicator v5 Oscillators & momentumVolatility & bands
Updated 4 years ago · None stated GitHub repository of Function - Logistic Equation

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

This indicator detects a Bollinger Band squeeze when the bands sit inside Keltner Channels, marking low volatility. It plots red dots during a squeeze and green dots when the bands are outside, in a separate pane. An optional histogram shows momentum as the cl

Indicator v6 Volatility & bandsOscillators & momentum
Updated 3 months ago · None stated GitHub repository of Bollinger Band Squeeze Detector
147 stars

This indicator generates trade entry signals and target levels optimized for 1-hour timeframes, designed for external signal extraction. It calculates 7-period and 16-period EMAs alongside 10-period RSI and ATR filters. Long signals occur when the fast EMA cro

Indicator v5 TrendOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of Signal Strategy 100 Candles of 1H Timeframe

Bubbles Indicator

by capissimo
114 stars

The Bubbles Indicator measures volatility squeezes and expansion bursts using Bollinger Bands combined with a sinusoid oscillator and RSI divergence. It processes price data through scaled Bollinger Bands to highlight volatility changes while confirming trend

Indicator v4 Volatility & bandsOscillators & momentum Repaints
Updated 1 year ago · None stated GitHub repository of Bubbles Indicator

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