Investment Studio > Expressions > Functions > Indicator > KB
float array[*][4] kb(float array[*][4] dhlc, integer ema_days = 20, integer atr_days = 10, float multiplier = 2, float previous_ema = 0)
Returns a four-column array containing dates and corresponding Keltner Band (KB) values. Each row is structured as follows:
| Column # | Content |
| 1 | The quote date. |
| 2 | The lower Keltner band value. |
| 3 | The central Keltner band value. |
| 4 | The upper Keltner band value. |
Given n input rows in dhlc, n - atr_days rows are returned.
dhlc is a four-column array containing daily price quotes. Each row is structured as follows:
| Column # | Content |
| 1 | The quote date. |
| 2 | The day's high (highest traded price). |
| 3 | The day's low (lowest traded price). |
| 4 | The day's close (last traded price). |
The array is assumed to be time-sorted, with earlier dates preceding later dates.
Automatic type conversion allows the use of date strings as arguments instead of explicit date values.
If only daily closes (but not highs and lows) are available, consider using Bollinger bands instead.
ema_days > 0 sets the timescale of the exponential moving average (see EMA) used to compute the central band value from daily closes. If omitted, ema_days defaults to 20.
atr_days > 0 is the number of trading days contributing to the computation of each day's average true range (see ATR). If omitted, atr_days defaults to 10.
multiplier is a factor applied to the ATR value in order to obtain the distance between the central band and the external bands. If omitted, multiplier defaults to 2.
previous_ema is the EMA value (= central band value) on the trading date preceding the first date quoted in dhlc. If omitted, previous_ema defaults to 0.
Interpretation
Keltner bands are an exponential moving average (see EMA) crossed with a volatility indicator (see ATR).
| The central band is just EMA(ema_days). | |
| The daily upper band value is obtained by adding multiplier * ATR(atr_days) to the central band value. | |
| The daily lower band value is obtained by subtracting multiplier * ATR(atr_days) from the central band value. |
The result is an adaptive envelope: it widens when price action becomes volatile and contracts when prices settle down.
Consider for instance Motorola (NYSE:MOT) from June 1 to December 31, 2001:

The chart shows Keltner bands (20 EMA days, 10 ATR days, multiplier = 2) superimposed on prices. Note how prices tend to gravitate to the lower band in downtrends and to the upper band in uptrends.
Like Bollinger bands and other envelope indicators, Keltner bands are designed so that the appropriate choice of parameters will confine prices within the envelope for most of the time. When price touches or moves outside an outer band, this signals an overbought condition (upper band) or an oversold condition (lower band). Such a condition does not by itself imply that a trend reversal is imminent, but once a reaction move does get started at an outer band it often goes all the way to the opposite band. This may be used to set price targets.
Example
Assuming standard US date format settings,
=kb({{"1/1/1990", 100, 90, 98}, {"1/2/1990", 97, 84, 86}}, 1, 1)
returns {{32875, 60, 86, 112}, {32876, 73, 91, 109}}. Zooming in on the first row, 32875 is the date code for 1/2/1990; 60 is the lower band value, 86 the central band value and 109 the upper band value for that date (with ema_days = atr_days = 1, default multiplier and default previous_ema).