Skip to content
All library documents

Efficient Linear Regression with Slope and Intercept

Article MQL5 code base

Summary

The document discusses an efficient way to calculate linear regression for trading indicators. It contrasts the conventional regression calculation, which provides both the fitted line’s intercept and slope, with a compact value calculation expressed as a weighted moving average and a simple moving average combination. The latter is described as suitable for an optimized, loop-free implementation and as producing correct regression values.

The central limitation is that the compact value-only method does not expose the regression slope or intercept as intermediate results. The proposed alternative aims to preserve those quantities while still using loop-free calculations for efficiency. The available text does not include the alternative’s derivation, implementation details, benchmark results, or validation examples, so its performance and numerical behavior cannot be independently assessed from this description. The discussion concerns calculation mechanics rather than a trading rule or evidence of predictive advantage.

Key ideas

  • A weighted-average and simple-average combination can calculate a linear regression value efficiently.
  • The value-only shortcut does not provide the regression intercept or slope.
  • An alternative calculation is proposed to retain both regression parameters while avoiding repeated loops.
  • The description provides no derivation, benchmark, or validation evidence for that alternative.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.