tbiktag

Repeated Median Regression Channel

tbiktag 업데이트됨   
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.

Method
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.


References
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. en.wikipedia.org/wik...ed_median_regression
릴리즈 노트:
The code is converted to PineScript v5. The core algorithms are transferred to the public library.
There are no changes in the functionality of the script.

To use the RM regression algorithm in conjunction with interactive inputs, you can also try this tool:

DISCLAIMER: I am not a financial advisor, and my scripts are for educational purposes only. Any trades you make are at your own risk.
오픈 소스 스크립트

이 스크립트의 오써는 참된 트레이딩뷰의 스피릿으로 이 스크립트를 오픈소스로 퍼블리쉬하여 트레이더들로 하여금 이해 및 검증할 수 있도록 하였습니다. 오써를 응원합니다! 스크립트를 무료로 쓸 수 있지만, 다른 퍼블리케이션에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

차트에 이 스크립트를 사용하시겠습니까?