DINEXSPACEXAUUSD SpecialistEAs available to rentCustom EA: Strategy → Code → BacktestView rentable EA bots
// ATR.MQ5

What is the ATR indicator?

Average True Range (ATR)Volatility

It does not show direction, only how strongly the market is moving — the basis for a sensible stop-loss.

What is Average True Range?

Measures the market's average volatility as a smoothed average of the True Range.

Average True Range (ATR) — ATR(14) 7.67 — SIMULATEDDINEXSPACE / VolatilityATR(14) 7.67XAUUSD · 1H / SIMULATEDRESSUP2,330.52,360.82,451.72,427.9▼ SELLCandle 99: SELL▲ BUYCandle 104: BUY▲ BUYCandle 111: BUYVOL*ATR · priceCANDLE 1CANDLE 29CANDLE 57CANDLE 85CANDLE 112MA · EMA 14 ━━━━ / VOL* · ILLUSTRATIVE CANDLE RANGEEMA 14Illustrative data — not real market data, not a trading signalAverage True Range (ATR) — ATR(14) 7.67 — SIMULATEDATR 14XAUUSD · 1H / SIMULATEDRESSUP2,427.9▲ BUYCandle 111: BUYVOL*ATR · priceAverage True Range (ATR) — ATR(14) 7.67 — SIMULATEDATR 14XAUUSD · 1H / SIMULATEDRESSUP2,330.52,427.9▲ BUYCandle 111: BUYVOL*ATR · priceAverage True Range (ATR) — ATR(14) 7.67 — SIMULATEDATR 14XAUUSD · 1H / SIMULATEDRESSUP2,330.52,427.9▲ BUYCandle 111: BUYVOL*ATR · priceEMA 14Illustrative data — not real market data, not a trading signal

Illustrative signals of the rule on simulated data — not a trading recommendation.

Rule: Price closes beyond the high/low of the previous 10 candles while ATR(14) rises: buy/sell in the breakout direction. Entry = close of the signal candle; SL = entry ∓ 1.5 × ATR(14); TP1/TP2/TP3 = 1R/2R/3R.

Use this indicator to create a Custom EA brief →
// WHY_USE_IT

Where this indicator is strong

Three reasons Average True Range is still used after decades.

A stop-loss based on the market

The stop distance is based on the real range, instead of a guessed fixed number of pips.

Position size can be calculated

Knowing the range lets you convert it into a volume so each trade risks exactly the intended share of capital.

Session filter

A very low ATR means the market is asleep; many systems stop trading during that phase.

// READING_SIGNALS

How to read Average True Range signals

How Average True Range (ATR) produces its number, and what each shape on the chart means.

Formula and how it works

Each candle's True Range is the largest of three values: (high − low), |high − previous close|, |low − previous close|. ATR is the Wilder-smoothed average of the True Range over N periods. A high ATR means high volatility; ATR does not show direction, only the size of the moves.

How to use it in an EA

Set Stop Loss and Take Profit as multiples of ATR to adapt to volatility; use ATR to filter out periods when the market is too quiet or too noisy.

Fits when

Any context — ATR is a risk management tool, not a tool for finding entries.

Struggles when

Using ATR as a buy/sell signal. It contains no directional information, so on its own it never says buy or sell.

ATR rises quicklyVolatility is expanding — often alongside news or a break of a price zone.
ATR stays low for a long timeThe market is consolidating. The stop-loss should tighten accordingly, not stay the same.
ATR is several times its usual levelA warning of slippage risk; position size should shrink, not stay the same.
Common mistakes

Keeping a fixed stop-loss distance while ATR has doubled. The trade then gets stopped out by the market's normal swings.

// PARAMETERS

Recommended MT5 parameters for Average True Range

Default values of the sample file; test them for your market and timeframe.

ParameterDescription
InpPeriodTrue Range smoothing period (default 14).
// INSTALL

Put the indicator into MetaTrader 5

Four steps, no software needed besides MT5.

01Download the .mq5 file

Click the download button above; the file saves to your computer under the indicator's name.

02Open the data folder

In MetaTrader 5 choose File → Open Data Folder, then go to MQL5/Indicators.

03Compile

Open the file in MetaEditor and click Compile. No errors means the indicator is ready.

04Drag it onto the chart

Go back to MT5, refresh the Navigator and drag the indicator onto the price chart.

📄 atr.mq5

DinexSpace wrote this file from the indicator's public formula, not from any commercial source. You are free to edit and reuse it.

// THE_DIFFERENCE

How it differs from MetaTrader 5's built-in indicator

The short answer: the formula is not different. What differs is what you can do with it.

Average True Range here gives exactly the same number as MetaTrader 5's built-in version — on purpose. The four points below are what differs, and all four can be read from the very atr.mq5 you download.

Calls a built-in indicator
No — the calculation sits in OnCalculate and can be copied straight into an EA
External libraries
Not a single #import declaration
Code length
53 lines · 1 input parameters
How it draws
A separate window below the price chart · calculated incrementally, does not redraw the past

Why this library promises no secret formula — read the full explanation on the library page.

// COMBINATIONS

Which indicators to pair Average True Range with, and what you gain

Each indicator only answers one question. Pairing well means covering the right weakness, not stacking more.

Average True RangeMoving Average
What you gain
The minimum pair for a trend system: the MA handles entries, ATR handles the stop distance and position size.
Note
This is the pair to build first. Without the sizing part, no signal, however good, becomes a system.
See Moving Average
Average True RangeBollinger Bands
What you gain
Cross-checks two ways of measuring volatility. A squeeze with a low ATR means the market is truly compressed.
Note
Bollinger measures the standard deviation of the close, ATR measures the full candle range including gaps — two different numbers.
See Bollinger Bands
Average True RangeAverage Directional Index
What you gain
Separates volatility from trend. A high ATR with a low ADX is a market that moves a lot but goes nowhere — the easiest phase to lose in.
Note
Neither indicator shows direction. This pair decides whether to trade, not whether to buy or sell.
See Average Directional Index
// FAQ

Frequently asked questions about Average True Range

Does ATR give buy/sell signals?

No, and that is not a flaw. ATR only measures the size of the swings and contains no directional information at all. Its role is to set the stop-loss distance and position size for another system.

How many ATRs should the stop-loss be?

1.5 to 2 times ATR is the common range. Smaller and the trade gets stopped out by normal swings; larger and each losing trade costs too much. What matters is keeping the multiple fixed and adjusting position size to it.

Does Average True Range on this page use real or simulated data?

The chart on this page uses a deterministic simulated candle series; it is not market prices or trading results.

// SAME_GROUP

Other volatility indicators

Indicators in the same volatility group, often used instead of or alongside Average True Range.

Turn Average True Range into an automated EA

An indicator draws signals, but when to enter, where to stop out and how much to risk are still your set of rules. Send those rules and DinexSpace builds them into an EA.

Use this indicator to create a Custom EA brief