tbiktag

Moving Regression

Moving Regression is a generalization of moving average and polynomial regression.

The procedure approximates a specified number of prior data points with a polynomial function of a user-defined degree. Then, polynomial interpolation of the last data point is used to construct a Moving Regression time series.

Application:
Moving Regression allows one to smooth noise on the analyzed chart, assess momentum, confirm trends, and establish areas of support and resistance .
In addition, it can be used as a simple stand-alone forecasting method to identify trend direction and trend​ reversal points. When the local polynomial is predicted to move up in the next time step, the color of the Moving Regression curve will be green. Otherwise, the color of the curve is red. This function is (de)activated using the Predict Trend Direction flag.

Selecting the ​model parameters:
The effects of the moving window Length and the Local Polynomial Degree are confounded. This allows for​ finding the optimal trade-off between noise (variance) and lag (bias). Higher Length and lower Polynomial Degree (such as 1, i.e. linear), will result in "smoother" time series but at the cost of greater lag. Increasing the Polynomial​ Degree to, for example, 2 (squared) while maintaining the Length will diminish the lag and thus compromise the noise-lag tradeoff.

Relation to other methods:
When the degree of the local polynomial is set to 0 (i.e., fitting data to a constant level), the Moving Regression time series exactly matches the Simple Moving Average of the same length.
Notas de Lançamento: minor corrections
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Quer usar esse script no gráfico?

Comentários

500moeda
+1 Resposta
tbiktag PineCoders
@PineCoders, Many thanks!
Resposta
This looks like the Least Squares Moving Average
+1 Resposta
tbiktag Dealth
@Dealth, In my experience, the name "Least Squares Moving Average" is commonly associated with local linear regression. The current script is built on polynomial regression and therefore can be viewed as a generalization. But of course you can achieve the local linear regression by setting Polynomial Degree to 1.
Resposta
This looks splendid. However I don't get the blue line to show up nor can I find how to activate it in settings. Help!
Thanks
Resposta
MMC11 MMC11
tbiktag- Perhaps you could send me the settings you use for a stock, because the one's I have do not produce two lines. No matter how I change them.
Resposta
tbiktag MMC11
@MMC11, the script produces only one line as output, i.e. the MR curve (plotted in green-red color). The blue line that you see in the preview is just the closing price.
Resposta
MMC11 tbiktag
@tbiktag, THAN!KS
Resposta
It would be nice if you add the derivative of the polinomial, not to be plotted, just to plot a shape y the expected vertice of the polinomilal or when the derivative=0. Your work is really cool
Resposta
tbiktag jesus.cgalaviz
@jesus.cgalaviz, many thanks for the feedback! As for the derivative, you might check out the recently added implementation of a smooth differentiator: .
It is not based on local polynomial regression, but often shows an even better trade-off between noise suppression and lag. One could also use it to differentiate the MR curve by choosing the latter as a source.
Resposta
Início Rastreador de Fundamentos Rastreador Forex Rastreador de Criptomoedas Calendário Econômico Como Funciona Recursos gráficos Preços Indique um Amigo Regras da Casa Central de Ajuda Soluções para Sites & Corretoras Widgets Soluções em Gráficos Biblioteca de Gráficos Lightweight Blog & Notícias Twitter
Perfil Configurações de perfil Conta e Cobrança Amigos indicados Moedas Meus Tíquetes de Suporte Central de Ajuda Mensagens Privadas Conversa Deslogar