Indicators · condition block
ATR (Average True Range)
The ATR block measures volatility with Wilder's Average True Range and compares it, as a percentage of the current close, with a threshold. Expressing ATR as a percentage keeps the same setting meaningful at $10,000 and at $100,000.
How the engine evaluates it
True range is the largest of: high minus low, the distance from the previous close to the high, and the distance from the previous close to the low. It captures gaps between candles.
ATR starts as the simple average of the first N true ranges and is then smoothed with Wilder's method: (previous ATR × (N − 1) + true range) / N.
The block divides ATR by the current close and compares the percentage strictly with your threshold. Before your start date the engine loads extra history (at least 50 candles, up to 5,000, scaled to the longest indicator in the bot) so the indicator has settled by the first candle of the run.
TR = max(high − low, |high − prev close|, |low − prev close|)
ATR[t] = (ATR[t−1] × (N − 1) + TR[t]) / N
ATR % = ATR / close × 100
Botscript syntax
In the Lab you pick this block from the Indicators group and fill in its fields. In the code view the same condition is written like this:
atr(14) > 1.5%
atr(14) < 0.8%
Settings
| Setting | Values | Default | Notes |
|---|---|---|---|
| Comparison | >, < | > | — |
| Threshold | 0 – 1,000% | 1.5% | Compared with ATR as a % of the close. |
| Length | 1 – 5,000 | 14 | — |
| Timeframe | the run's candles, or 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d, 1w | the run's candles | Optional. At least the run's candle size and a whole multiple of it. |
On a higher timeframe
Add a timeframe at the end to read ATR from bigger candles than the run uses, for example atr(14) > 3% on 1d. The engine builds those candles from the run's own candles (UTC, weeks start on Monday) and evaluates the block only on candles that have closed, so there is no look-ahead. Lengths and lookbacks count the bigger candles.
ATR is a state on a higher timeframe: the result from the last completed bigger candle holds on every run candle until the next one closes.
The timeframe must be at least the run's candle size and a whole multiple of it; otherwise the run stops with an error and is not charged. Multi-timeframe conditions covers the details, including warm-up.
How traders use it
- Avoid dead markets:
atr(14) > 1%on entries. - Avoid chaos:
atr(14) < 4%to skip trading in extreme volatility. - Pick volatility regimes for breakout or mean-reversion systems.
Example bot
bot "Volatile Breakouts Only"
when breakout high 48 and atr(14) > 1.2%
then buy 100%
when breakout low 24
then sell 100%
- Takes 48-candle breakouts only when ATR is above 1.2% of price.
- Exits on a 24-candle low.
Pitfalls
- ATR depends on the candle size: a 1-hour ATR of 1% is a calm day's daily ATR. Re-tune when changing timeframe.
- ATR says how much price moves, not which way.
ATR: frequently asked questions
Why is ATR a percentage here?
Bitcoin's price has changed by orders of magnitude since 2017. A percentage keeps one threshold valid across the whole history.
Is this Wilder's ATR?
Yes: true range smoothed with Wilder's running average, seeded with the simple average of the first N true ranges.
What is the difference from the volatility block?
ATR includes gaps from the previous close and uses Wilder smoothing. The volatility block is a plain average of each candle's high-to-low range.
Can I set a stop at so many ATRs?
Use the chandelier exit block (highest high minus k × ATR) or Supertrend, which are both built on ATR.
Related blocks
Simulated results are hypothetical. They include only the fee and slippage you set on the bot, not every real-world cost or market condition, and past performance does not guarantee future results. Nothing here is financial advice.