Keltner Channels (kc)
[[kc]] produces three series: a middle line and two bands that form an adaptive envelope around it. The middle line is an exponential moving average of source, representing the smoothed level of that series. The upper and lower bands remain equally distant from this center.
The spacing between the bands follows recent candle ranges, widening as those ranges expand and narrowing as they contract. length sets the smoothing horizon for both the center and the spacing, while multiplier controls the distance of the bands. use_true_range selects either True Range, which accounts for gaps from the previous close, or the candle’s high - low range alone.
Block declaration
A strategy can contain multiple [[kc]] blocks.
Each block produces three series: upper channel, middle line, and lower channel. Each series is identified using the keys upper_id, middle_id, and lower_id.
Examples
Minimal setup
This block computes Keltner Channels using the block defaults: source = "close", length = 20, multiplier = 2.0, and use_true_range = true.
[[kc]]
upper_id = "kc_up"
middle_id = "kc_mid"
lower_id = "kc_low"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.
[[kc]]
upper_id = "kc_up"
middle_id = "kc_mid"
lower_id = "kc_low"
source = "hl2"
length = 14
multiplier = 1.5
use_true_range = falseSearch for the optimal period and multiplier
This block explores ranges of values for length and multiplier to identify the best-performing combination.
[[kc]]
upper_id = "kc_up"
middle_id = "kc_mid"
lower_id = "kc_low"
length.start = 10
length.stop = 30
length.step = 1
multiplier.start = 1.0
multiplier.stop = 3.0
multiplier.step = 0.25Channel breakout filter
This example uses the upper band as a breakout filter. On each candle, the [[condition]] block only lets the strategy move on when close > kc_up, meaning price closes above the upper channel.
[[kc]]
upper_id = "kc_up"
middle_id = "kc_mid"
lower_id = "kc_low"
[[condition]]
id = "channel_breakout"
condition = "close > kc_up"
next_block_id = "..."Dedicated symbol and timeframe
This Keltner Channels 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.
[[kc]]
upper_id = "kc_up"
middle_id = "kc_mid"
lower_id = "kc_low"
symbol = "BINANCE:ETHUSDT"
timeframe = "D"Parameters
| Parameter | Description |
|---|---|
upper_idString Required | Name of the upper channel series. Example: upper_id = "kc_up" |
middle_idString Required | Name of the middle line series. Example: middle_id = "kc_mid" |
lower_idString Required | Name of the lower channel series. Example: lower_id = "kc_low" |
sourceString 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" |
lengthInteger 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) |
multiplierDecimal Optional | Multiplier applied to the range EMA to calculate the upper and lower bands; 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_rangeBoolean 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 |
symbolString 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. |
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 identifiers below directly in your expressions. The Keltner Channels block exposes three numeric series (upper, middle, lower), their parameters, the middle-line input series, the price sources used for the range, the symbol, and the timeframe.
Assume the block is configured as:
[[kc]]
upper_id = "kc_up"
middle_id = "kc_mid"
lower_id = "kc_low"Then:
| Variable | Description |
|---|---|
kc_up or kc_up[0]Decimal | Current upper channel value. |
kc_mid or kc_mid[0]Decimal | Current middle EMA line value. |
kc_low or kc_low[0]Decimal | Current lower channel value. |
kc_up[n]kc_mid[n]kc_low[n]Decimal | Upper channel value from n candles ago. Middle line value from n candles ago. Lower channel value from n candles ago. |
kc_up.lengthkc_mid.lengthkc_low.lengthDecimal | Period used for the middle-line EMA and the range EMA. |
kc_up.multiplierkc_mid.multiplierkc_low.multiplierDecimal | Multiplier applied to the range EMA. |
kc_up.use_true_rangekc_mid.use_true_rangekc_low.use_true_rangeDecimal | Range calculation mode: 1 when True Range is used, 0 when the block uses high - low. |
kc_up.sourcekc_mid.sourcekc_low.sourceString | Name of the series used for the middle EMA line. |
kc_up.high_sourcekc_mid.high_sourcekc_low.high_sourceString | Name of the high series used to calculate the range. |
kc_up.low_sourcekc_mid.low_sourcekc_low.low_sourceString | Name of the low series used to calculate the range. |
kc_up.close_sourcekc_mid.close_sourcekc_low.close_sourceString | Name of the close series used to calculate True Range when use_true_range = true. |
kc_up.symbolkc_mid.symbolkc_low.symbolString | Symbol used by this output. |
kc_up.timeframekc_mid.timeframekc_low.timeframeString | Timeframe used by this output. |
Notes
- The bands are calculated symmetrically around the middle line:
upper channel = middle + multiplier × EMA(range)andlower channel = middle - multiplier × EMA(range). - Numeric variables support arithmetic, comparisons, and logical operators.
- Text variables are strings intended for equality/inequality checks only.