atr
Average True Range
atr(periods, matype="wilder")
Parameters
| Name | Type | Description |
|---|---|---|
periods |
int | Number of periods (commonly 14) |
matype |
str, optional | Smoothing type ["wilder", "sma", "ema"], default "wilder" |
Formula
```
True Range = MAX(high - low, |high - prev_close|, |low - prev_close|)
ATR = MA(True Range, periods)
```
Examples
// bar range exceeded ATR
(high - low) > atr(14);
/* range exceeded to the downside; simple moving aveage smoothing for true range calc */
low < open - atr(14, matype="sma");
/* atr higher (expanded volatility) than 5 bars ago */
myatr = atr(14, matype="sma");
myatr > myatr[5];
/* strong move exceeds 2x ATR */
close > close[1] + 2 * atr(14);
Returns
Float value representing the average true range (always positive)