ATR (Average True Range)
How much does it usually move in a day?
The average size of a day's full price swing in ₹, overnight gaps included.
ATR on a chart of past prices
Settings: move a slider and the chart redraws
How many days of ranges are averaged. 14 is the standard.
How far under the highest close the rule's stop sits.
The rule buys a close above the highest close of this many days.
What it measures
A day's true range is the biggest of three distances: high minus low, the gap from yesterday's close up to today's high, and the gap from yesterday's close down to today's low. It counts overnight gaps that a plain high-minus-low would miss.
ATR is the average true range of the last 14 days, smoothed the Wilder way (13 parts yesterday's ATR, 1 part today's range). It is in ₹: an ATR of ₹25 means the stock has typically swung about ₹25 a day lately.
ATR says nothing about direction. Traders use it to choose how many shares to buy and where to put a stop-loss that fits how much the stock normally moves.
How traders read it
- Rising ATR: bigger daily swings, more risk per share. Falling ATR: a calmer stock.
- Compare ATR with the price: ₹25 is 1% of a ₹2,500 stock but 5% of a ₹500 one.
- A common stop-loss sits 2 to 3 ATRs below the entry, far enough that an ordinary day does not hit it.
- The red dashed line on the chart is the stop the rule below uses: 3 ATRs under the highest close since it bought.
The traps
No direction
A high ATR can come from a crash or a rally. ATR on its own is never a reason to buy or sell.
In ₹, not %
Comparing ATRs across stocks without dividing by the price is meaningless.
Calm can end suddenly
Today's ATR describes the last 14 days. A results announcement or a market shock can make tomorrow's swing several times bigger.
Test the classic rule: Breakout with an ATR trailing stop
Waiting for prices…
Quick check
Waiting for prices…
Use it in a script
function run(bars, ta, helpers) {
const closes = helpers.closes(bars);
const atr = ta.wilderAtr(bars, 14);
const signals = [];
let inTrade = false, best = 0;
for (let i = 20; i < bars.length; i++) {
const prevHigh = Math.max(...closes.slice(i - 20, i)); // highest close of the previous 20 days
if (!inTrade && closes[i] > prevHigh && atr[i] !== undefined) {
signals.push(helpers.buy(i));
inTrade = true;
best = closes[i];
} else if (inTrade) {
best = Math.max(best, closes[i]); // best close since buying
if (closes[i] < best - 3 * atr[i]) { // fell more than 3 ATRs below it
signals.push(helpers.sell(i));
inTrade = false;
}
}
}
return signals;
}This is the rule tested above, with the settings on your sliders, and it gives exactly the same buy and sell candles. Paste it into the Scripts drawer of the chart workbench, or save it and compare it across stocks in the Strategy Lab. New to scripts? The Writing strategies track starts from zero.
In the reference:ta.wilderAtr