Repeated Median Regression with Interactive Range Selection

tbiktag Aktualisiert   
Greetings to all!
As you probably know, TradingView now supports interactive inputs that can be directly set on a chart. I decided to build a tool that takes advantage of this incredible feature. This tool applies robust linear regression within a time interval on the chart that you can select interactively.

The script uses an algorithm known as Repeated Median Regression. It belongs to the class of so-called robust regression methods. The reason they are called “robust” is that these methods are much less sensitive to outliers in the data than the ordinary least squares.

The calculation procedure is as follows: For each data point, this algorithm collects the slopes of the lines connecting that point to all other points in the sample, calculates the median slope, and then obtains the median value of these median slopes. Subsequently, it calculates the intercepts of the regression line and the mean absolute error (MAE) of the model.

Based on these results, a linear channel is plotted. The upper and lower channel boundaries are set by the MAE value multiplied by a user-defined coefficient.

Further reading
You can read more about robust linear regression on Wikipedia.
For more information on interactive inputs, see the User Manual's page.

Previous publication
I have already posted a script using the repeated median regression method. Although the core algorithm is essentially the same, interactive input provides fundamentally different functionality to the current script.

A word of caution
Currently, the interactive interval selection mode can be triggered only when the script is loaded to the chart. Thus, you might have to reload it when switching between different timeframes.
The core algorithms are transferred to the public library. There are no changes in the functionality of the script.
An option has been added to mark the beginning and end of the selected interval on the chart ("Show Interval Borders").

DISCLAIMER: I am not a financial advisor, and my scripts are for educational purposes only. Any trades you make are at your own risk.
Open-source Skript

Ganz im Spirit von TradingView hat der Autor dieses Skripts es als Open-Source veröffentlicht, damit Trader es besser verstehen und überprüfen können. Herzlichen Glückwunsch an den Autor! Sie können es kostenlos verwenden, aber die Wiederverwendung dieses Codes in einer Veröffentlichung unterliegt den Hausregeln. Sie können es als Favoriten auswählen, um es in einem Chart zu verwenden.


Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.

Möchten Sie dieses Skript auf einem Chart verwenden?