Keltner Channels
Install and import
npm install fintech-algorithmsimport { keltner_channels } from "fintech-algorithms/technical-indicators/volatility-and-channels/keltner-channels";Signature
keltner_channels(high, low, close, emaPeriod, atrPeriod, multiplier)An EMA with bands placed a number of ATRs away. Because it scales with true range rather than standard deviation, it reacts differently to gaps than Bollinger Bands — which is the basis of the squeeze comparison between the two.
Parameters
| Name | Type | Notes |
|---|---|---|
high | number[] | Per-bar high prices, chronological. |
low | number[] | Per-bar low prices, chronological. |
close | number[] | Per-bar closing prices, chronological. |
emaPeriod | number | Span of the EMA that forms the middle line. min: 1 · integer: true |
atrPeriod | number | Wilder period for the ATR that sets the band width. min: 1 · integer: true |
multiplier | number | Number of ATRs from the middle line to each band. min: 0 |
Returns
Record<string, (number | null)[]> · length same-as-input
Parallel series: true_range, atr, middle, upper and lower.
Warm-up
The first max(emaPeriod, atrPeriod) positions are null.
Errors
- When either period is < 1, is not an integer, or multiplier is negative — throws RangeError
- When the input series are not all the same length — throws RangeError
Complexity: time O(n),
space O(n).
Worked example
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input
[101.08, 101.6243955, 102.13058177, 102.56507653, 102.90321818, 103.1320792]Showing 6 of 240 elements.
[98.92, 99.39457765, 99.83203556, 100.19996391, 100.47473988, 100.64442473]Showing 6 of 240 elements.
[100, 100.50948657, 100.98130867, 101.38252022, 101.68897903, 101.88825197]Showing 6 of 240 elements.
20102Call
keltner_channels(high, low, close, emaPeriod, atrPeriod, multiplier)Returns
object with 5 fields: true_range, atr, middle, upper, lower
{
"true_range": [
2.1599999999999966,
2.2298178500000034,
2.298546210000012,
2.365112620000005,
2.4284782999999948,
2.4876544700000096
],
"atr": [null, null, null, null, null, null],
"middle": [null, null, null, null, null, null],
"upper": [null, null, null, null, null, null],
"lower": [null, null, null, null, null, null]
}Other exports
This module also exports
true_range, average_true_range. Every module additionally exports run as an alias of its
primary function, and a meta object carrying its catalog id, domain, family,
shape and article URL.
Diagrams
How it works
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References
- Keltner Channels (KC) — TradingView
- New Concepts in Technical Trading Systems — J. Welles Wilder Jr.
- Average True Range — TA-Lib
- True Range — TA-Lib
- Public evidence boundary