Commodity Channel Index (cci)

[[cci]] measures the gap between a price series and its recent behavior. You can use it to spot extension phases, filter specific market conditions, or compare several settings in a grid search.

The CCI oscillates around zero. A positive value means the observed series is trading above its recent level, while a negative value means it is trading below it. The farther the value moves away from zero, the stronger the deviation. In practice, some users also watch the +100 and -100 areas to identify moves that are already well extended.

Block declaration

A strategy can contain multiple [[cci]] blocks. Each block outputs one numeric series: the CCI value.

Examples

Minimal setup

This block computes CCI with a 20-period window. Since source is omitted, the block uses the default hlc3 source.

[[cci]]
id     = "cci"
length = 20

Finding the optimal length

This block explores a range of values for length to identify the best-performing length. Since source is omitted, the block uses the default hlc3 source.

[[cci]]
id           = "cci"
length.start = 10
length.stop  = 30

Momentum filter with threshold

This example uses the CCI as a momentum filter. cci_threshold defines the minimum level that must be exceeded for the condition to become true. Lower thresholds make the filter more permissive, while higher thresholds only keep phases where the deviation from recent behavior is more pronounced.

[[constant]]
id    = "cci_threshold"
start = 50
stop  = 150
step  = 10

[[cci]]
id     = "cci"
length = 20

[[condition]]
id            = "cci_filter"
condition     = "cci > cci_threshold"
next_block_id = "..."

Dedicated timeframe

This CCI block uses a separate daily timeframe. The series used to compute the CCI is taken from that timeframe (timeframe = "D"), not from the main timeframe defined in [backtest]. See the Exchanges, Symbols and Timeframes page for alignment rules between this timeframe and the main timeframe.

[[cci]]
id        = "cci"
timeframe = "D"
length    = 20

Specific symbol

This block reads its price series from the specific symbol BINANCE:ETHUSDT. See the Exchanges, Symbols and Timeframes page for alignment with the main symbol.

[[cci]]
id     = "cci"
symbol = "BINANCE:ETHUSDT"
length = 20

Parameters

ParameterDescription
id
 String
 Required
Unique name for the CCI series.
source
 String
 or Array
 Optional
Input series used for the calculation.
Accepted forms: source = "hl2" or source = ["close", "hl2"].
Each value can be either a standard price source (open, close, high, low, hl2, hlc3, ohlc4, hlcc4, volume) or the id of another indicator.
Default value: "hlc3"
length
 Integer
 Required
Observation window; must be ≥ 2.

Usage:
• Fixed: length = value
• Grid search:
 – length.start = min_value
 – length.stop = max_value
 – length.step = value (optional, default 1)
symbol
 String or Array
 Optional
Market symbol(s) used when source only consists of standard prices (open, close, high, low, hl2, hlc3, ohlc4, hlcc4, volume).
If source mixes standard prices and indicator ids, symbol is applied only to combinations based on standard prices.
If source contains only indicator ids, symbol is ignored.
If omitted, the block inherits the symbol defined in [backtest].
For symbol format, arrays, and alignment rules, see Exchanges, Symbols and Timeframes.
timeframe
 String or Array
 Optional
Timeframe on which this indicator is computed.
If timeframe is omitted, the computation uses the grid’s main timeframe defined in [backtest].
For accepted formats and timeframe alignment rules, see Exchanges, Symbols and Timeframes.

Available variables

Use the identifier below directly in your expressions. The CCI block exposes one numeric series and its parameters (length, source, symbol, timeframe).

Assume the block is configured as:

[[cci]]
id     = "cci"
length = 20

Then:

VariableDescription
cci or cci[0]
Decimal
Current CCI value.
cci[n]
Decimal
CCI value from n candles ago.
cci.length
Decimal
Window length currently in use (works with fixed or grid‑searched ranges).
cci.source
String
Name of the input series (e.g., hlc3, close, or another indicator id).
cci.symbol
String
Symbol used (display string).
cci.timeframe
String
Timeframe used for this CCI.

Notes

  • The series returns na until enough history is available to compute the CCI, and also in some windows where the measured deviation becomes zero.