Commodity Channel Index (cci)
The Commodity Channel Index (CCI) places the current value of a series relative to its recent mean while accounting for the series’s usual dispersion over the same window. It produces an unbounded oscillator centered on zero. A positive value means that the source is above its mean, while a negative value means that it is below.
The magnitude of the CCI expresses the size of that gap relative to recent dispersion. The same absolute gap therefore produces a larger magnitude when the series is usually stable and a smaller one when it is usually more dispersed. length defines the common window used for the mean and dispersion. CCI thus describes a normalized deviation rather than a distance expressed in the unit of the source.
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 from the default hlc3 source. Since length is omitted, the block uses the default length 20.
[[cci]]
id = "cci"Custom fixed setup
This block uses a custom length value.
[[cci]]
id = "cci"
length = 30Finding 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 = 30Momentum 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 symbol and timeframe
This CCI block uses the daily price series from BINANCE:ETHUSDT, independently of the primary symbol and timeframe defined in [backtest]. See Exchanges, Symbols and Timeframes for alignment rules.
[[cci]]
id = "cci"
symbol = "BINANCE:ETHUSDT"
timeframe = "D"
length = 20Parameters
| Parameter | Description |
|---|---|
idString Required | Unique name for the CCI series. |
sourceString 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" |
lengthInteger Optional | Observation window; must be ≥ 2 when specified. If length is omitted, the default value is 20.Usage: • Fixed: length = value• Grid search: – length.start = min_value– length.stop = max_value– length.step = value (optional, default 1) |
symbolString 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. |
timeframeString 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"Then:
| Variable | Description |
|---|---|
cci or cci[0]Decimal | Current CCI value. |
cci[n]Decimal | CCI value from n candles ago. |
cci.lengthDecimal | Window length currently in use (works with fixed or grid‑searched ranges). |
cci.sourceString | Name of the input series (e.g., hlc3, close, or another indicator id). |
cci.symbolString | Symbol used (display string). |
cci.timeframeString | Timeframe used for this CCI. |
Notes
- The series returns
nauntil enough history is available to compute the CCI, and also in some windows where the measured deviation becomes zero.