Durbin Watson Test Statistic [pig]

In statistics, the Durbin–Watson statistic is a test statistic used to detect the presence of autocorrelation at lag 1 (AR(1) process) in the residuals (prediction errors) from a regression analysis. With the new array function tradingview implemented, we are able to do our calculations on the residuals.

The residual is given by subtracting the actual value (in this case it's log returns) from the prediction value (generated by linear regression ). The following chart displays who we get the error term from the regression.
Then we do our calculation based on the residuals. The formula is basically sum of squared of the difference between error and it's 1 lagged term divided by sum of squared of all the error terms. It's a very simple test on residual sum of squares. The value you get is from 0 to 4.
When DW > 2, there's a possible negative autocorrelation.
When DW < 2, there's a possible positive autocorrelation.
Note: above 2 and below 2 is only possible autocorrelation, it might not be statistically significant.

If we want to know if the autocorrelation presence is significant or not. We need a Durbin Watson Stats Table. Based on the lookback period you use, you can find the critical value on the table (usually the first column).
Durbin Watson 0. 05 Table
For the default setting 30 lookbacks, the 5% critical level for positive autocorrelation is 1.35. (We round to 1.4 on the default setting for convenience ). The other side for negative autocorrelation is just 4 - 1.35 = 2.65 due to its symmetry. For other lookbacks like 50, the critical value is 1.5 and 2.5, we just need to check the table to find the corresponding value. The user only has to find the lower threshold, the indicator will automatically give you the 4- lower threshold value on the other side.

As we have mentioned in the autocorrelation function and Hurst exponent . Positive autocorrelation means positive returns are more likely to be followed by positive returns and negative returns are more likely to be followed by negative returns. People may call it trending. Negative autocorrelation means positive returns are more likely to be followed by negative returns and negative returns may be followed by positive returns. People may call it mean-reverting.
The Durbin Watson test only tests the first-order autocorrelation. But there might also be significant autocorrelation in other lagged values. You can see the autocorrelation of other lags in our ACF.
We may also publish more advanced autocorrelation tests in the future.
Release Notes: A typo in graph one displaying the error as distance between the points and the regression line. "E5" should be "E3".
Release Notes: Implemented 0.05 Significance Dubrin Watson Statistics Table in the code. No need to check the table or type in the critical value. The value will be automatically adjusted according to the lookback period.

Changed the color theme.

White means DW > 2, possible - autocorrelation / mean reversion
Orange means DW < 2, possible + autocorrelation / trending

Blue background means DW > upper critical value, Significant - autocorrelation / mean reversion
Red background means DW < lower critical value, Significant + autocorrelation / trending

Skript med en öppen källkod

I sann TradingView-anda har författaren till detta skript publicerat det som öppen källkod, så att handlare kan förstå och verifiera det. Skål för författaren! Du kan använda den gratis men återanvändning av den här koden i en publikation regleras av våra Ordningsregler. Du kan göra den till favorit för att använda den i ett diagram.

Vill du använda det här skriptet i ett diagram?
Our Website🅱🅰🐷:

Sign up on our website to get access to our indicators.

Join Our Discord for further discussions:


500 coins
This publication is now featured in our Editors' Picks. In the name of all TradingView traders, thank you for your valuable contribution to the TradingView community, and congrats!
+11 Svara
balipour PineCoders
@PineCoders, I was trying to find where I was saying there should be another word for “help” that actually helps. And that’s all you guys have done for us every single time there was an opportunity. So I want to thank you for being great and providing the greatest platform to allow us to do what we do. Thank you.
+8 Svara
PineCoders balipour
@balipour, Thx for the good words. Appreciate. Without exceptional creations such as yours, there would be nothing for us to select for Editors' Picks, so thanks to you guys for your work, and for sharing it open-source.
+5 Svara
balipour PineCoders
@PineCoders, far too kind.
+4 Svara
+9 Svara
balipour DairyMilk
@DairyMilk, one person gets it lol.
+2 Svara
Kommentar borttagen.
balipour CryptoCYCLOPS
@CryptoCYCLOPS, Happy Birthday my man. Least we could do, lol.
+1 Svara

Thanks Bali/Pig!
+3 Svara