Linreg trends
Price bands around a moving average of closes, showing the range recent closes normally sit in.
Despite the name, this indicator fits no regression line. It takes the simple average of the last window closes as a centre line, then draws a lower band num_std standard deviations below it and an upper band the same distance above. The bands widen when recent closes are spread out and narrow when they bunch together. The slope outputs show how far the centre line moved over the last window bars, in percent.
How to read it
- Both bands are drawn on the price chart, one above and one below the moving average of recent closes.
- With the default 2 standard deviations, a close outside the bands is unusual for the last 50 bars.
- Narrow bands mean recent closes are bunched; widening bands mean the spread is growing. In a steady trend both bands drift with price.
- The pane below shows the moving average's slope in percent: above 0 the average rose, below 0 it fell. On the SPY sample 90% of readings fell between -0.19% and +0.19%.
What it outputs
- Lower band
- The moving average minus num_std standard deviations of the last window closes. Catalog output mins.
- Upper band
- The moving average plus num_std standard deviations of the same closes. Catalog output maxs, the mirror image of the lower band.
- Average slope
- Percent change of the moving average over the last window bars. Above 0 the average rose, below 0 it fell. Catalog output mins_slope.
- Average slope (repeat)
- The same series as Average slope. The code returns the one slope object twice, so this line duplicates Average slope.
Settings
- window
- Bars in the moving average, the standard deviation and the slope look-back. Longer smooths the average and makes the slope a longer move; shorter makes the bands follow the last few minutes. At 1 both bands sit on the close.
- num_std
- Distance of each band from the average, in standard deviations. Raising it widens both bands equally; lowering it pulls them in, and at 0 both sit on the average. Below 0 the lower band jumps above the upper one. The slope lines do not change.
Pitfalls
- The name is misleading: no regression is fitted. These are Bollinger-style statistical bands, not proven support or resistance levels.
- Band width uses the spread of closing prices, not bar-to-bar moves, so a steady trend widens the bands even when the noise is small.
- The two slope lines are identical, and the chart starts blank: the bands need window bars and the slope needs about twice that.