Atr trends
A moving-average envelope set by recent volatility, with its percent slope in a pane below.
The center is an exponential moving average of the close, with smoothing factor 2 divided by ema_window plus 1. The true range of each bar is averaged with Wilder smoothing over atr_window bars to give the ATR. The lower and upper lines are the center minus and plus atr_mult times that ATR, so they widen when bars get larger. The two slope outputs are the percent change of the center over the last ema_window bars.
How to read it
- The two lines sit on the candles, around the average of the close. Price moving between them is normal.
- At defaults on SPY one-minute bars the lines sit only about 0.3 dollars from the average.
- A close beyond a line means price moved more than atr_mult typical bar ranges away from the average.
- In the pane below, a slope above zero means the average is rising and below zero means it is falling.
What it outputs
- Lower band
- The average minus atr_mult times the ATR. It follows the average up and down, so it is a volatility floor, not a past price low.
- Upper band
- The average plus atr_mult times the ATR. It follows the average up and down, so it is a volatility ceiling, not a past price high.
- Band slope (lower)
- Percent change of the average over the last ema_window bars. Identical to the upper band slope, so only one line shows.
- Band slope (upper)
- Percent change of the average over the last ema_window bars. Identical to the lower band slope, so the two lines overlap.
Settings
- ema_window
- Length of the average the bands center on. Raising it smooths the center and slows the bands. Lowering it makes the bands hug price closely. It also sets the slope lookback, so the slope covers the same number of bars.
- atr_window
- Bars used to average the true range into the band width. Shorter reacts to each recent bar, so the bands breathe with every swing. Longer gives a steadier width that changes slowly.
- atr_mult
- How many ATRs the bands sit from the average. Raising it widens both lines so fewer closes land outside. Lowering it tightens them. Zero puts both lines on the average, and negative values swap the lower and upper lines.
Pitfalls
- Despite the support and resistance names in the code, these lines are not past highs or lows. A touch of the lower line is not a tested floor.
- The module docstring calls the slope percent per bar, but the code measures percent change over ema_window bars. The two slope outputs are the same series.
- Under Wilder smoothing a single large bar loses only 1/14 of its weight per bar at the default atr_window of 14, so the bands stay wide for a while after a spike.