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.
版本注释: A typo in graph one displaying the error as distance between the points and the regression line. "E5" should be "E3".
版本注释: 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

从常用脚本中删除 添加到常用脚本
Our Website🅱🅰🐷:

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

Join Our Discord for further discussions:


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 回复
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 回复
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 回复
balipour PineCoders
@PineCoders, far too kind.
+3 回复
+9 回复
balipour DairyMilk
@DairyMilk, one person gets it lol.
+1 回复
Just waking up, what a post B-Day surprise. BaliPig bringing the heat as usual, you 2 guys are setting the standard in the Math revolution. Say goodbye to outdated indicators and hello to Better Math.
Mafffs McBagginz approves, 2 thumbs up from the Discord @ POWB.......
+7 回复
balipour CryptoCYCLOPS
@CryptoCYCLOPS, Happy Birthday my man. Least we could do, lol.
+1 回复

Thanks Bali/Pig!
+3 回复
首页 股票筛选器 外汇筛选器 加密货币筛选器 财经日历 如何运作 图表功能 价格 推荐朋友 网站规则 帮助中心 网站 & 经纪商解决方案 插件 图表解决方案 轻量图表库 博客 & 新闻 Twitter
概览 个人资料设置 账户和账单 推荐朋友 代币 我的客服工单 帮助中心 已发表观点 粉丝 正在关注 私人消息 在线聊天 退出