Skip to content
All library documents

Smooth Theil-Sen Regression with Robust Trend and Deviation Bands

Article TradingView scripts

Summary

The indicator estimates a trend line with a Theil-Sen regression: it computes slopes across pairs of observations and combines them with selectable mean, median, or kernel-weighted smoothing. It derives the intercept from residuals, then plots the fitted line and upper and lower deviation bands. Users can choose median absolute deviation or root mean square deviation for band width, and the code supports an offset and extensions beyond the fitted window.

The design offers a tradeoff between robustness and smoothness: medians reduce sensitivity to outliers, while mean-based choices are more affected by extreme values; RMS deviation is also more sensitive to large residuals than MAD. The supplied excerpt is implementation-focused and provides no trading rules, empirical comparison, or backtest results. The bands therefore describe a statistical visualization method, not evidence of a profitable strategy.

Key ideas

  • The Theil-Sen trend estimate is built from pairwise slopes rather than a single ordinary least-squares fit.
  • Mean, median, and kernel-weighted options let users trade smoothness against robustness to outliers.
  • Deviation bands can use median absolute deviation or root mean square deviation.
  • The indicator plots the regression center line and its upper and lower bands, with optional projection features.
  • The document supplies no trading rules or performance evidence for the indicator.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.