Concept 24 / 52·Volatility·Bands and channels
‹ Inside BarMACD ›

Keltner Channels in Pine Script

Keltner channel · KC · ATR channel · EMA ATR channel

An EMA with lines a multiple of ATR above and below it, a smoother volatility channel than Bollinger Bands, used for breakouts, pullbacks and the squeeze.

Reads best on: Trending markets on 1-hour to daily charts: futures, forex majors, large caps and the main crypto pairs. The channel is a poor guide in low-volatility ranges, where outside closes are noise.
On this page: the Pine v6 script, checked, drawn on real NVDA bars. Backtest it free, costs charged, every trade on the chart.
Backtest results: Keltner Channel strategy: SPY, QQQ and more since 2016, costs charged, every trade listed.
01

Definition

Keltner Channels are a moving average with a line drawn a multiple of the average true range above it and another the same distance below. The modern form uses a 20-period exponential moving average and lines 1.5 ATR away. They sit in the bands and channels family beside Bollinger Bands and envelopes, and the difference is the unit of width: ATR, the average of each bar's full range including gaps, rather than the standard deviation of closes or a fixed percentage. The result is a smoother channel that changes width gradually.

ATR measures how much the market moves in a typical bar. A channel 1.5 ATR either side of the trend line therefore marks the zone of ordinary movement around the trend, and a close outside it is a bar that has travelled further than the usual range allows. That is a momentum event, and it is why Keltner traders mostly use the channel for breakouts and trend riding rather than for fading. Because ATR is smoothed and includes every bar's range, the channel does not jump on a single volatile close the way a deviation band does.

Chester Keltner published the original version in 1960 as a 10-day rule: a simple average of the typical price with bands from the 10-day average of the daily range. Linda Raschke's later version, an exponential average with ATR-based lines, is the one platforms ship today, usually 20 for the average, 10 or 20 for the ATR and a multiplier of 1.5. The library script uses one length for both the EMA and the range average with a 1.5 multiplier, and it marks a long on a close above the upper line and a short on a close below the lower line.

On the chart price spends most of its time inside the channel, drifting around the mid line. In a trend the mid line slopes and price repeatedly returns to it, so the mid line is the pullback level. A strong move closes outside the channel and can keep closing outside it for several bars; the first close back inside is the pause. The channel widens slowly as volatility rises and narrows slowly as it falls, and when the Bollinger Bands drop inside the Keltner channel the market is in a squeeze, the low-volatility regime that precedes expansion.

02

Reading the chart

Read the mid line for direction, the lines for the limit of ordinary movement, and the width for the volatility regime.

  1. Read the slope of the mid line, the 20-period EMA. Rising means the trend is up and the long side carries the trend; falling means down; flat means a range where outside closes are more likely to fade.
  2. Locate the close relative to the lines. Inside the channel is ordinary movement; a close beyond a line is a move larger than the recent average range allows, the momentum event the library script marks.
  3. Treat the mid line as the pullback level in a trend. Returns to it that hold, with the channel still sloping, are the pullback entries in the trend's direction.
  4. Watch the first close back inside after a run outside. It marks the pause, and whether price then holds the mid line or breaks it tells you if the trend continues.
  5. Judge the width. A channel that has narrowed for many bars, especially with the Bollinger Bands inside it, is compressed, and the next outside close is more likely to start a run than to fade.
  6. Note the timeframe. Outside closes on 5-minute charts are frequent and mostly noise; on 1-hour to daily charts they are rarer and carry more information.
03

The maths

The mid line is an exponential moving average and the channel lines are that average plus and minus a multiple of the average true range.

Midt=EMAn(C)\mathrm{Mid}_t = \mathrm{EMA}_n(C)
TRt=max⁡(Ht−Lt, ∣Ht−Ct−1∣, ∣Lt−Ct−1∣)\mathrm{TR}_t = \max\left(H_t - L_t,\, \lvert H_t - C_{t-1} \rvert,\, \lvert L_t - C_{t-1} \rvert\right)
ATRt=ATRt−1 (n−1)+TRtn\mathrm{ATR}_t = \frac{\mathrm{ATR}_{t-1} \, (n - 1) + \mathrm{TR}_t}{n}
Uppert=Midt+m ATRt\mathrm{Upper}_t = \mathrm{Mid}_t + m \, \mathrm{ATR}_t
Lowert=Midt−m ATRt\mathrm{Lower}_t = \mathrm{Mid}_t - m \, \mathrm{ATR}_t
CCthe series of closes
EMAn\mathrm{EMA}_nthe exponential moving average over n bars
HtH_tthe high of bar t
LtL_tthe low of bar t
Ct−1C_{t-1}the close of the previous bar
nnthe length, 20 by default, used for the EMA and the range average
mmthe ATR multiplier, 1.5 by default
TRt\mathrm{TR}_tthe true range of bar t
ATRt\mathrm{ATR}_tthe average true range at bar t, Wilder smoothed
ATRt−1\mathrm{ATR}_{t-1}the average true range of the previous bar
Midt\mathrm{Mid}_tthe mid line
Uppert\mathrm{Upper}_tthe upper channel line
Lowert\mathrm{Lower}_tthe lower channel line

The original 1960 channel used a simple average of the typical price and the plain high-to-low range. The modern form swaps in an EMA and the true range, which counts gaps.

Wilder's ATR smooths the true range with a weight of 1 / n. The library script uses the platform's built-in channel, which averages the true range with an exponential average over the same length as the EMA, a slightly livelier version of the same idea.

The multiplier is 1.5 by convention. Breakout systems use 2 to 2.5 so that an outside close is rare; tight pullback systems use 1 and go long on returns to the lower line in an uptrend.

The squeeze compares this channel with Bollinger Bands of the same length. The Bollinger Bands and Volatility Squeeze articles carry that reading.

04

Inputs that matter

InputTypicalWhat changing it does
EMA length20Shorter turns the mid line and the channel faster and produces more outside closes; longer gives a calmer channel that trends ride for longer.
ATR multiplier1.5Lower puts price outside the lines more often, which adds signals and noise; higher makes an outside close a rarer, stronger momentum event.
05

In practice

  • As a breakout trigger: a close above the upper line in a rising channel is the momentum entry the library script marks, and a close below the lower line in a falling one is the short.
  • As a pullback framework: in a trend, the rule waits for price to return to the mid line and resume, an entry with a closer stop than the outside close, below the channel.
  • As the outer half of the squeeze: when the Bollinger Bands sit inside the Keltner channel the market is compressed, and the release is traded in the direction of momentum.
  • As a trend exit: a close back through the mid line against the trade, or a close outside the opposite line, is a mechanical place to leave a trend trade.
  • As a distance measure: how far price sits from the mid line in ATR units tells you whether an entry is extended, and it is comparable across instruments and timeframes.
  • As a reversion frame in ranges: when the mid line is flat, outside closes tend to fade back to it, the opposite trade from the breakout reading and only taken with a range confirmed.
06

Where it goes wrong

  • Trading outside closes as breakouts in a flat channel. Without slope they are stretches that revert; check the mid line before going long on strength.
  • Reading Keltner widths like Bollinger widths. ATR moves slowly, so a Keltner channel that looks narrow is not the same signal as pinched Bollinger Bands; use the two together.
  • Setting the multiplier too small. At 1 ATR price is outside on a quarter of the bars and every signal is noise; start at 1.5 and go up for breakout systems.
  • Ignoring the timeframe. An outside close on a 1-minute chart is a routine event, and the rule that works on 4-hour bars produces constant whipsaws there.
07

Compared with

Bollinger Bands. Bollinger Bands are built from the standard deviation of closes and react quickly to a cluster of wide bars. Keltner channels use smoothed ATR and change width gradually, so they are the calmer reference, and the pair defines the squeeze.

Average True Range. ATR is the unit and the Keltner channel is one use of it: a trend line with an ATR corridor around it. The ATR article covers stops, targets and sizing; this one covers the corridor.

Moving Average Envelopes. Envelopes place lines a fixed percentage from an average, so their width ignores volatility. Keltner lines sit a multiple of ATR away, so the corridor breathes with the market and one setting travels across instruments.

SuperTrend. SuperTrend is an ATR band that flips sides and stays on one side of price as a stop. A Keltner channel keeps both lines on the chart, does not flip, and asks you to read the mid line for direction.

08

Build it in Quant

Type one of these in the Quant desk, or click it. A request that fits a checked template is assembled on the spot without a credit; anything beyond the blanks goes to the copilot, which edits on top of the checked script.

Open Keltner Channels on the workbench chart
Drawn on real data; then audit, backtest and refine in conversation.
Open in Quant →
09

Questions

  • Keltner channels or Bollinger Bands, which should I use?

    They answer different questions. Bollinger Bands measure how dispersed closes are and react fast, which suits reversion and squeeze detection. Keltner channels measure ordinary range around a trend and change slowly, which suits breakouts and pullbacks. Many traders keep both on the chart and read the squeeze from their relationship.

  • Why 1.5 ATR?

    It is the setting Raschke's version made standard, and it places the lines so that price is inside on most bars and outside on the ones that matter. At 1 ATR outside closes are routine; at 2 or more they are rare and better suited to slow breakout systems. Treat 1.5 as the reference and move it only after testing.

  • Can Keltner channels be used for mean reversion?

    Yes, in a range. When the mid line is flat, a close outside a line is a stretch that usually returns to the mid line, and the trade is the return. The library script marks outside closes as breakouts, so a reversion read treats its marks as the opposite side, and only with a flat mid line and a confirmed range.

  • What ATR length does the channel use?

    Platforms differ. Many use a 10-period ATR with a 20-period EMA; the library script uses one length for both, 20 by default. A shorter ATR makes the width react sooner to a change in range, a longer one keeps it steadier. The difference on a chart is small next to the effect of the multiplier.

  • Why does a Keltner breakout look late?

    Because the close has to travel 1.5 average ranges from a smoothed average before it counts. That distance is the filter: it removes the small pokes that fail and keeps the moves with momentum. If it feels late on your timeframe, look for the pullback to the mid line after the breakout rather than lowering the multiplier.

  • Can I use the lower line as a trailing stop?

    You can, and in a steady uptrend it works: the lower line rises with the EMA and sits about 1.5 ATR below the trend, a reasonable stop distance. It is not ratcheted, so it can move down when the average dips. For a stop that never retreats, use the Chandelier exit or a trailing stop with the same ATR distance.