Trend Quality R-Squared
Two markets can travel the same net distance over the same number of bars and be completely different trades: one grinds in a near-straight line, the other whipsaws back and forth and only nets out in the same direction by the end of the window. A slope or a moving-average crossover cannot tell these apart because both only look at where price ended up, not how it got there. R-squared answers a different question: of all the variation in price over the window, how much is explained by a straight line through it. A value near 1.0 means price tracked the line closely; a value near 0 means the line barely describes what happened even if its slope is technically correct. The calculation uses the standard shortcut that, for a simple linear regression, R-squared equals the square of the Pearson correlation between bar index and price - this avoids ever constructing the fitted line itself, just the correlation sums. House style does not allow the DRAW_COLOR_LINE type that would normally paint a single line two colours by trend direction, so the score is instead split across two buffers by the fit's own slope sign: green while the fit sloped up, red while it sloped down. Notes and limitations - R-squared measures how well price fit a straight line over the window, it does not measure how large that move was - a small, clean drift and a large, clean drift can score identically. - A very short InpPeriod can produce a high score from just a couple of bars moving in the same direction, which is a low-confidence reading no matter what the number says; the level lines are a starting point, not a guarantee. - This is a descriptive, backward-looking measure. A high score describes the window that just closed, not what happens next.
Indicator · MT5 · v1.0 · Free
About Trend Quality R-Squared
Trend Quality R-Squared is an indicator for MetaTrader 5. It has 1 setting, such as Period. MQL source code included.
Files in the download: TrendQualityRsquared.ex5, TrendQualityRsquared.mq5, TrendQualityRsquared.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Period | 20 | Bars in the rolling linear-fit window |
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 → Indicators.
- 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 indicator from the Navigator onto a chart and adjust the settings.
Tags: Trend · MT5 Indicator · MQL5 Source Code