OPEN-SOURCE SCRIPT

Quadratic & Linear Time Series Regression [SS]

Hey everyone,

Releasing the Quadratic/Linear Time Series regression indicator.

About the indicator:
Most of you will be familiar with the conventional linear regression trend boxes (see below):

cuplikan

This is an awesome feature in Tradingview and there are quite a few indicators that follow this same principle.
However, because of the exponential and cyclical nature of stocks, linear regression tends to not be the best fit for stock time series data. From my experience, stocks tend to fit better with quadratic (or curvlinear) regression, which there really isn't a lot of resources for.

To put it into perspective, let's take SPX on the 1 month timeframe and plot a linear regression trend from 1930 till now:

cuplikan

You can see that its not really a great fit because of the exponential growth that SPX has endured since the 1930s. However, if we take a quadratic approach to the time series data, this is what we get:

cuplikan

This is a quadratic time series version, extended by up to 3 standard deviations. You can see that it is a bit more fitting.

Quadratic regression can also be helpful for looking at cycle patterns. For example, if we wanted to plot out how the S&P has performed from its COVID crash till now, this is how it would look using a linear regression approach:

cuplikan

But this is how it would look using the quadratic approach:

cuplikan

So which is better?

Both linear regression and quadratic regression are pivotal and important tools for traders. Sometimes, linear regression is more appropriate and others quadratic regression is more appropriate.

In general, if you are long dating your analysis and you want to see the trajectory of a ticker further back (over the course of say, 10 or 15 years), quadratic regression is likely going to be better for most stocks.

If you are looking for short term trades and short term trend assessments, linear regression is going to be the most appropriate.

The indicator will do both and it will fit the linear regression model to the data, which is different from other linreg indicators. Most will only find the start of the strongest trend and draw from there, this will fit the model to whatever period of time you wish, it just may not be that significant.

But, to keep it easy, the indicator will actually tell you which model will work better for the data you are selecting. You can see it in the example in the main chart, and here:

cuplikan

Here we see that the indicator indicates a better fit on the quadratic model.

And SPY during its recent uptrend:

cuplikan

For that, let's take a look at the Quadratic Vs the Linear, to see how they compare:

Quadratic:
cuplikan

Linear:
cuplikan

Functions:
You will see that you have 2 optional tables. The statistics table which shows you:

  • The R Squared to assess for Variance.
  • The Correlation to assess for the strength of the trend.
  • The Confidence interval which is set at a default of 1.96 but can be toggled to adjust for the confidence reading in the settings menu. (The confidence interval gives us a range of values that is likely to contain the true value of the coefficient with a certain level of confidence).
  • The strongest relationship (quadratic or linear).


Then there is the range table, which shows you the anticipated price ranges based on the distance in standard deviations from the mean.

cuplikan

The range table will also display to you how often a ticker has spent in each corresponding range, whether that be within the anticipated range, within 1 SD, 2 SD or 3 SD.

You can select up to 3 additional standard deviations to plot on the chart and you can manually select the 3 standard deviations you want to plot. Whether that be 1, 2, 3, or 1.5, 2.5 or 3.5, or any combination, you just enter the standard deviations in the settings menu and the indicator will adjust the price targets and plotted bands according to your preferences. It will also count the amount of time the ticker spent in that range based on your own selected standard deviation inputs.

Tips on Use:

  • This works best on the larger timeframes (1 hour and up), with RTH enabled.
  • The max lookback is 5,000 candles.
  • If you want to ascertain a longer term trend (over years to months), its best to adjust your chart timeframe to the weekly and/or monthly perspective.



And that's the indicator! Hopefully you all find it helpful.
Let me know your questions and suggestions below!

Safe trades to all!
forecastingregressionsstatistics

Skrip open-source

Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menerbitkannya sebagai sumber terbuka, sehingga para trader dapat memahami dan memverifikasinya. Hormat untuk penulisnya! Anda dapat menggunakannya secara gratis, namun penggunaan kembali kode ini dalam publikasi diatur oleh Tata Tertib. Anda dapat memfavoritkannya untuk digunakan pada chart

Inggin menggunakan skrip ini pada chart?


For real-time updates and premium indicators, consider joining my group at: patreon.com/steversteves
Juga di:

Pernyataan Penyangkalan