Keltner Channels Width (kcw)

[[kcw]] condenses the Keltner Channel envelope into a single series: the distance between the upper and lower bands divided by their middle line. When the middle line and the band width are expressed in compatible units, typically with a positive price source, a high value describes a wide channel relative to its center, while a low value describes a narrow one. The series measures the spacing of the envelope, not the position of price inside it.

In that case, the output reads as a ratio rather than a displayed percentage: 0.025 means that the channel width is 2.5% of the middle line. This relative reading removes the effect of the absolute price level. When source uses a different unit, the quotient no longer has this usual relative interpretation.

Block declaration

A strategy can contain multiple [[kcw]] blocks. Each block outputs one numeric series, identified by id.

The block reads source to compute the middle line. It also reads high, low, and close to compute the Keltner Channels range. When use_true_range = false, close is still exposed as an internal source, but the range used by the calculation is high - low.

Examples

Minimal setup

This block computes Keltner Channels Width using the block defaults: source = "close", length = 20, multiplier = 2.0, and use_true_range = true.

[[kcw]]
id = "kcw"

Custom fixed setup

This block uses hl2 for the middle line, a 14-candle window, a 1.5 multiplier, and the simple high - low range instead of True Range.

[[kcw]]
id             = "kcw"
source         = "hl2"
length         = 14
multiplier     = 1.5
use_true_range = false

Search for the optimal period and multiplier

This block explores ranges of values for length and multiplier to identify the most useful combination for measuring channel expansion or contraction.

[[kcw]]
id = "kcw"

length.start = 10
length.stop  = 30
length.step  = 1

multiplier.start = 1.0
multiplier.stop  = 3.0
multiplier.step  = 0.25

Volatility filter

This example uses kcw as a volatility filter. The [[constant]] block defines a threshold named kcw_threshold whose value ranges from 0.01 to 0.04 during the grid search. On each candle, the [[condition]] block only lets the strategy move on when kcw > kcw_threshold, meaning the channel is wide enough relative to its middle line.

[[kcw]]
id = "kcw"

[[constant]]
id    = "kcw_threshold"
start = 0.01
stop  = 0.04
step  = 0.005

[[condition]]
id            = "volatility_filter"
condition     = "kcw > kcw_threshold"
next_block_id = "..."

Dedicated symbol and timeframe

This Keltner Channels Width block uses the daily candles from BINANCE:ETHUSDT. The middle line and the high, low, and close prices needed for the range come from this symbol and timeframe, independently of the primary symbol and timeframe defined in [backtest]. See Exchanges, Symbols and Timeframes for alignment rules.

[[kcw]]
id        = "kcw"
symbol    = "BINANCE:ETHUSDT"
timeframe = "D"

Parameters

ParameterDescription
id
 String
 Required
Unique name identifying the Keltner Channels Width series; the block exposes one numeric series with this identifier.
source
 String
 or Array
 Optional
Input series used to calculate the middle EMA line.
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: "close"
length
 Integer
 Optional
Period used for both the middle-line EMA and the range EMA; must be at least 1. Default value: 20.

Usage:
• Fixed: length = value with value >= 1
• Grid search:
 – length.start = min_value with min_value >= 1
 – length.stop = max_value
 – length.step = value (optional, default 1)
multiplier
 Decimal
 Optional
Multiplier applied to the range EMA before calculating the channel width; must be strictly greater than 0. Default value: 2.0.

Usage:
• Fixed: multiplier = 2.0
• Grid search:
 – multiplier.start = min_value with min_value > 0
 – multiplier.stop = max_value
 – multiplier.step = value (optional, default 1)
use_true_range
 Boolean
 Optional
Selects the range used for the channel width.
If true, the block uses True Range. If false, it uses high - low.
Default value: true
symbol
 String
 or Array
 Optional
Market symbol(s) used for the high, low, and close prices needed by the range, and for source when source contains standard price series.
If source references another indicator, symbol does not replace that source series; it still applies to the high, low, and close prices used for the channel width.
If omitted, the block inherits the [backtest] symbol.
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

The Keltner Channels Width block exposes one numeric series, its parameters, the middle-line input series, the price sources used for the range, the symbol, and the timeframe.

Assume the block is configured as:

[[kcw]]
id = "kcw"

Then:

VariableDescription
kcw or kcw[0]
Decimal
Current relative width of the Keltner Channels.
kcw[n]
Decimal
Relative width from n candles ago.
kcw.length
Decimal
Period used for the middle-line EMA and the range EMA.
kcw.multiplier
Decimal
Multiplier applied to the range EMA.
kcw.use_true_range
Decimal
Range calculation mode: 1 when True Range is used, 0 when the block uses high - low.
kcw.source
String
Name of the series used for the middle EMA line.
kcw.high_source
String
Name of the high series used to calculate the range.
kcw.low_source
String
Name of the low series used to calculate the range.
kcw.close_source
String
Name of the close series used to calculate True Range when use_true_range = true.
kcw.symbol
String
Symbol used by this output.
kcw.timeframe
String
Timeframe used by this output.

Notes

  • Relative width is calculated as (upper channel - lower channel) / middle line.
  • When the middle line is zero, the series value is not available (NaN).
  • When the middle line is negative, the ratio is negative and the usual interpretation as a positive width does not apply directly.
  • Band width is derived from the high and low prices, and from close when use_true_range = true, while the middle line comes from source. If source is volume or another indicator expressed in a different unit, the quotient mixes incompatible units and cannot be interpreted as a dimensionless relative width or percentage.
  • Numeric variables support arithmetic, comparisons, and logical operators.
  • Text variables are strings intended for equality/inequality checks only.