Rolling Regression Diagnostics
This library does not fit anything itself. It is deliberately regression-agnostic: hand it an actual[] series and the predicted[] series your own fitting method produced (a moving-average channel, a linear trend line, a least-squares library elsewhere in your code) and it reports how well the fit is holding up, over a rolling window rather than one static figure for the whole history. R-squared and adjusted R-squared report how much of the actual series' variance the predictions explain. RMSE gives the error in the same units as the data. Durbin-Watson flags residual autocorrelation - a value drifting away from 2.0 toward 0 means residuals are running in one direction for stretches at a time, a classic sign the model is missing real structure rather than the leftover being pure noise. The residual normality panel (skewness, excess kurtosis, and the Jarque-Bera statistic) checks whether the residuals still look like the noise a well-specified regression should leave behind, or whether they carry the fat tails and asymmetry of a regime the fit no longer describes. Jarque-Bera is asymptotically chi-square with 2 degrees of freedom under the null hypothesis of normal residuals, which has the closed-form p-value exp(-JB/2) - no numerical integration or approximation needed for that particular p-value. Notes and limitations - Purely diagnostic - this library never fits a regression itself, only evaluates one you already computed. The actual[] and predicted[] arrays must be the same length and index-aligned. - The Jarque-Bera p-value uses the asymptotic chi-square(2) distribution, which is exact only in the large-sample limit. For rolling windows under roughly 30-40 points, treat the p-value as a rough guide rather than a precise significance test - the statistic itself remains a useful comparative measure across windows either way. - Durbin-Watson here is computed WITHOUT the standard published critical- value lookup tables (those depend on both sample size and number of predictors, and are normally read off a table rather than computed analytically) - use the standard "near 2 is good, toward 0 or 4 is concerning" reading rather than a formal significance test. - RrdRollingScan recomputes each window from scratch rather than updating incrementally window-to-window - fine for the window counts a chart-driven diagnostic panel needs, not optimised for scanning millions of windows in a backtest.
Script · MT5 · v1.0 · Free
About Rolling Regression Diagnostics
Rolling Regression Diagnostics is a script for MetaTrader 5. It has 2 settings, such as Series length and Window size. MQL source code included.
Files in the download: RollingRegressionDiagnostics.mq5.mqh, RollingRegressionDiagnostics.txt, RollingRegressionDiagnosticsDemo.ex5, RollingRegressionDiagnosticsDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Series length | 80 | Total number of synthetic points in the series |
| Window size | 20 | Rolling window length fed to RrdRollingScan |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Channels & Envelopes · Trend · MT5 Script · MQL5 Source Code