Repeated Median Regression Channel

This script uses the Repeated Median ( RM ) estimator to construct a linear regression channel and thus offers an alternative to the available codes based on ordinary least squares.

The RM estimator is a robust linear regression algorithm. It was proposed by Siegel in 1982 (1) and has since found many applications in science and engineering for linear trend estimation and data filtering.

The key difference between RM and ordinary least squares methods is that the slope of the RM line is significantly less affected by data points that deviate strongly from the established trend. In statistics, these points are usually called outliers, while in the context of price data, they are associated with gaps, reversals, breaks from the trading range. Thus, robustness to outlier means that the nascent deviation from a predetermined trend will be more clearly seen in the RM regression compared to the least-squares estimate. For the same reason, the RM model is expected to better depict gaps and trend changes (2).

Input Description
  • Length: Determines the length of the regression line.
  • Channel Multiplier: Determines the channel width in units of root-mean-square deviation.
  • Show Channel: If switched off, only the (central) regression line is displayed.
  • Show Historical Broken Channel: If switched on, the channels that were broken in the past are displayed. Note that a certain historical broken channel is shown only when at least Length / 2 bars have passed since the last historical broken channel.
  • Print Slope: Displays the value of the current RM slope on the graph.

Calculation of the RM regression line is done as follows (1,3):
  • For each sample point (t(i), y(i)) with i = 1..Length, the algorithm calculates the median of all the slopes of the lines connecting this point to the other Length-1 points.
  • The regression slope is defined as the median of the set of these median slopes.
  • The regression intercept is defined as the median of the set {y(i) – m*t(i)}.

Computational Time
The present implementation utilizes a brute-force algorithm for computing the RM-slope that takes O(Length^2) time. Therefore, the calculation of the historical broken channels might take a relatively long time (depending on the Length parameter). However, when the Show Historical Broken Channel option is off, only the real-time RM channel is calculated, and this is done quite fast.

1. A. F. Siegel (1982), Robust regression using repeated medians, Biometrika, 69, 242–244.
2. P. L. Davies, R. Fried, and U. Gather (2004), Robust signal extraction for on-line monitoring data, Journal of Statistical Planning and Inference 122, 65-78.
3. https://en.wikipedia.org/wiki/Repeated_m...
Mã nguồn mở

Với tinh thần của TradingView, tác giả đã xuất bản tập lệnh theo mã nguồn mở, vì thế trader có thể dễ dàng hiểu và tùy chỉnh được. Bạn có thể sử dụng miễn phí, hoặc tùy chỉnh lại mã đã được cấp phép bởi Quy tắc Chung. Bạn có thể sử dụng nó trên biểu đồ.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?

Bình luận

Great Work!
100 xu
Phản hồi
tbiktag TedPham
@TedPham, Thanks a lot!
Phản hồi
How to use this indicator
+1 Phản hồi
tbiktag tilakkatowal
@tilakkatowal, Basically, the script aims finding a linear channel that fits the price data within the window defined by the Length parameter. If you see that the fitted channel describes the data reasonably, you can consider the lower and upper boundaries of the channel as the potential support and resistance lines.
Phản hồi
Thank you for sharing ! Testing it !
+1 Phản hồi
tbiktag gmeneguzzo
@gmeneguzzo, you are welcome! Feel free to share your experience in the comments.
Phản hồi
Is there a way to scan a watchlist for the steepest angle/ slope? Or to get an alert when slope is at a certain angle?
Phản hồi
Hi Mate, It looks really good...I understand that we can take upper and lower band as Resistance and Support respectively. However, could please brief on the how to use the same.
Phản hồi
Is it possible to show 21,63 and 126 day simple regression lines (with no upper and lower bounds)? My coding this has thus far failed!! Thanks
Phản hồi
tbiktag grimweasel
@grimweasel, Not sure if I understood your point but you can remove the upper and lower lines from the plot simply by deactivating the "Show Channel" checkbox in the input window. Also when you want to see regression lines with three different lengths in the same chart, you can simply import three versions of this indicator
Phản hồi
Trang chủ Bộ lọc cổ phiếu Bộ lọc Forex Bộ lọc Tiền điện tử Lịch kinh tế Giới thiệu Tính năng Biểu đồ Trả phí Giới thiệu bạn Quy tắc Áp dụng Trung tâm Trợ giúp Giải pháp cho Website & Nhà môi giới Widget Giải pháp biểu đồ Thư viện Biểu đồ Lightweight Blog & Tin tức Twitter
Hồ sơ Tùy chỉnh Hồ sơ Tài khoản và Thanh toán Giới thiệu bạn Xu Ticket Hỗ trợ của tôi Trung tâm Trợ giúp Tin nhắn riêng Trò chuyện Đăng xuất