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.
//@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.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Length
int
20
i_p
Bull
input
C_GOLD
i_c_bull
Bear
input
C_VIOLET
i_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.
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
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
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
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
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
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