# ATR Bands (Keltner Channel) Indicator for MT4

> Keltner-style ATR bands: a moving average of your choice with upper and lower bands set a multiple of ATR away, for trend and volatility context.

## At a glance

- What it is: A free Indicator for MetaTrader 4, written in MQL4.
- What it does: Keltner-style ATR bands: a moving average of your choice with upper and lower bands set a multiple of ATR away, for trend and volatility context.
- Shared by: Alex
- Licence: MIT
- Version: 1.0 (1 Dec 2026)
- Settings: 11 inputs
- Lab check: Compiled with MetaEditor build 2425 for MT4 on 1 Dec 2026: 0 errors, 0 warnings.
- Price: Free to download
- Page: https://hub.fxnook.com/atr-bands-keltner-channel-indicator-for-mt4
- Download (compiled): https://hub.fxnook.com/download/1f033f29-762c-4333-ada3-461e86ed92d0/compiled
- Download (source): https://hub.fxnook.com/download/1f033f29-762c-4333-ada3-461e86ed92d0/source

## About

ATR Bands draws a moving average with an upper and a lower band placed a set number of Average True Ranges away. It works like a Keltner Channel: the bands widen when the market becomes more volatile and narrow when it calms down, so you can judge whether a move is stretched, where a volatility-based stop could sit, and which way the average is pointing.

## How it works

- **Middle line**: a moving average of the chosen price. SMA is the plain average of the last N prices, EMA uses `2 / (N + 1)` as weight, SMMA (smoothed) uses `(previous x (N - 1) + price) / N`, and LWMA gives the newest bar the largest weight. EMA and SMMA start from an SMA seed.
- **ATR**: Wilder's Average True Range over its own period, seeded with a simple average.
- **Bands**: `upper = MA + multiplier x ATR` and `lower = MA - multiplier x ATR`.

Only the newest bar is recalculated on each tick; the full history is worked out once when the indicator loads.

## Inputs

| Input | Default | What it does |
|---|---|---|
| MA period | 20 | Number of bars in the middle moving average. |
| MA type | EMA | SMA, EMA, SMMA or LWMA. |
| Applied price | Close | Price used for the average (close, open, high, low, median, typical, weighted). |
| ATR period | 14 | Number of bars in the ATR. |
| Multiplier | 2.0 | Band distance in ATRs. |
| Band colour | Steel blue | Colour of the upper and lower bands. |
| Middle colour | Goldenrod | Colour of the moving average. |
| Show middle | true | Shows or hides the middle line (its values stay available to `iCustom`). |

## How to use it

1. In MetaTrader choose **File > Open Data Folder**.
2. MT4: copy `FXN_AtrBands.mq4` into `MQL4/Indicators`. MT5: copy `FXN_AtrBands.mq5` into `MQL5/Indicators`.
3. Restart the terminal, or right-click **Indicators** in the Navigator and choose **Refresh**. If the indicator does not appear, open the file in MetaEditor and press F7 to compile it.
4. Drag the indicator onto a chart, adjust the inputs and press OK.

Start with EMA 20, ATR 14 and multiplier 2.0, a common Keltner setting. For a tighter channel use 1.5; for wider stop references try 2.5 or 3.0. Typical uses: a close outside the band in the direction of the average's slope as a sign of momentum, the middle line as a pullback area in a trend, or the opposite band as a reference for a stop.

## Good to know

- **Forming bar:** the values on the current bar change with price until it closes. Closed bars do not change.
- The ATR is calculated inside the indicator with Wilder smoothing, so it matches the standard ATR indicator.
- Unlike Bollinger Bands, the band width follows the average true range, not the standard deviation of closes, so it reacts less to a single large close.
- Price outside a band is not a signal by itself; in strong trends price can ride along one band for a long time.
- Buffers for `iCustom`: 0 upper, 1 middle, 2 lower. Works on any symbol and timeframe. It does not trade.

Trading carries risk. Test on a demo account first; past results do not predict future results.

## Settings (inputs)

| Input | Type | Default | Note |
|---|---|---|---|
| InpSep1 | string | === Middle line === | ---- Middle line ---- |
| InpMaPeriod | int | 20 | Moving average period |
| InpMaMethod | ENUM_MA_METHOD | MODE_EMA | Moving average type (SMA, EMA, SMMA, LWMA) |
| InpPrice | ENUM_APPLIED_PRICE | PRICE_CLOSE | Price used for the moving average |
| InpSep2 | string | === Bands === | ---- Bands ---- |
| InpAtrPeriod | int | 14 | ATR period (Wilder smoothing) |
| InpMultiplier | double | 2.0 | Band distance in ATRs |
| InpSep3 | string | === Display === | ---- Display ---- |
| InpBandColor | color | clrSteelBlue | Colour of the upper and lower bands |
| InpMiddleColor | color | clrGoldenrod | Colour of the middle line |
| InpShowMiddle | bool | true | Show the middle line |

Tags: atr, keltner-channel, bands, volatility, moving-average, indicator

Shared code is the author's work, not financial advice. Test on a demo account first.
