Discussing the article: "Online Linear Regression with Recursive Least Squares in MQL5: A Parameter-Free Adaptive Trend Estimator"
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Check out the new article: Online Linear Regression with Recursive Least Squares in MQL5: A Parameter-Free Adaptive Trend Estimator.
This article implements recursive least squares in native MQL5 with a constant O(1) update per bar, avoiding the per‑bar O(n) rebuild of a rolling OLS. It derives and codes the Sherman–Morrison rank‑1 update, explains the forgetting factor through its effective window, and provides a reusable class. Two coordinated indicators plot a 1‑step‑ahead price forecast on the chart and the signed slope in a correctly scaled subwindow for practical trend tracking.
A standard rolling-window OLS indicator rebuilds its normal matrix from all observations in the window on every bar. For a 200-bar window, that is 200 accumulation steps before a single coefficient is produced. For a 1000-bar window it is 1000 steps — five times the work, and this entire calculation is discarded and rebuilt when the next bar arrives, even though 999 of the 1000 observations are unchanged.
This is an O(n) cost per bar, where n is the window size. Summed across a full chart history it becomes O(n²). On a daily chart with a modest lookback this rarely matters. On a tick chart, or when the same logic runs across dozens of symbols, it becomes a real bottleneck.
RLS replaces the full rebuild with a fixed-cost update. The filter stores the current coefficient estimate and a compact representation of the inverse covariance matrix and updates both using only the newest observation via the Sherman-Morrison rank-1 formula. The update requires the same small number of scalar operations whether the filter has seen 20 bars or 200,000. That is O(1) per bar, independent of history length.
Author: Ushana Kevin Iorkumbul