kcw
Keltner Channels Width (percentage)
kcw(source, length, mult, matype="ema", atr_length=..., atr_matype="wilder", bandstyle="atr")
Parameters
Keltner Channels Width - kcw(source, length, mult, matype="ema", atr_length=None, atr_matype="wilder", bandstyle="atr")
Measures the width of Keltner Channels as a percentage of the middle line.
- source (field): Price field for middle line calculation (typically close)
- Valid inputs: close, open, high, low, or any indicator output
- length (int): Period for middle line MA calculation
- Common values: 20, 10, 50
- mult (float): Multiplier for band width
- Common values: 2.0, 1.5, 2.5
- matype (str, optional): MA type for middle line
- Valid options: ["ema", "sma", "wma", "wilder"]
- Default: "ema"
- atr_length (int, optional): Period for volatility calculation
- Default: None (uses same as length)
- atr_matype (str, optional): MA type for ATR smoothing
- Valid options: ["wilder", "sma", "ema"]
- Default: "wilder"
- bandstyle (str, optional): Volatility measurement method
- "atr": Use ATR (average true range)
- "truerange": Use raw true range
- "range": Use Wilder MA of (high - low)
Formula
middle = MA(source, length, matype)
upper = kc_upper(source, length, mult, ...)
lower = kc_lower(source, length, mult, ...)
width = ((upper - lower) / middle) * 100
Examples
kcw_value = kcw(close, 20, 2.0);
kcw_value < 10; # Narrow channels (low volatility, potential breakout)
kcw_value > 30; # Wide channels (high volatility)
# Squeeze detection (compare with Bollinger Bands Width)
kc_width = kcw(close, 20, 2.0);
bb_width = bb_width(close, 20, 2.0);
kc_width < bb_width; # Squeeze condition
Returns
Float value representing channel width as percentage of middle line
- Higher values indicate higher volatility (wider channels)
- Lower values indicate lower volatility (narrower channels)
- Useful for identifying volatility contraction/expansion