Least Correlated Candidate Selector
A scanner or a group of signal-generating EAs producing more candidates than there are free position slots usually gets resolved by taking the highest score and ignoring the rest. That fills every slot with whatever scored best right now, which is frequently three near-duplicates of the same underlying move - three JPY crosses all firing on one yen headline, for example - leaving the book far less diversified than the slot count suggests. This EA reads a shared candidate file, InpCandidateFile, that any external scanner or another EA can write to: one row per candidate, symbol, direction and a numeric score. When a free slot exists under this EA's own magic number, it builds a close-to-close return series for every candidate and for every currently held symbol, computes each candidate's average absolute Pearson correlation against the whole current book, and selects the candidate with the lowest average correlation - using the score only to break a near-tie between two similarly-uncorrelated candidates. A candidate whose lowest achievable correlation still exceeds InpMaxAllowedCorrelation is rejected outright rather than forced in just because a slot happened to be open. With an empty book, every candidate is equally uncorrelated by definition, so the first slot simply takes the highest-scored candidate; the diversification effect only engages from the second position onward, which is exactly when it matters. Notes and limitations - This EA only opens positions; it never closes one, and it has no opinion on exits - pair it with separate exit management on the same magic number, or manage exits manually. - A candidate or held symbol without enough loaded history for InpCorrelationBars is treated as maximally correlated (1.0) rather than ignored, so a data gap can never accidentally win the "least correlated" comparison. - The candidate file is read fresh every check interval and is not consumed or rewritten - the same candidate can be re-evaluated on every pass until a slot opens for it or it is removed from the file by whatever writes it. - Correlation is computed pairwise against every currently held symbol and averaged; it does not account for direction (long vs short), only the strength of the price-return relationship. - A symbol already held under this EA's own magic number is treated as maximally correlated against itself, so it is never selected a second time while already open.
Expert advisor · MT4 · v1.0 · Free
About Least Correlated Candidate Selector
Least Correlated Candidate Selector is an expert advisor (trading robot) for MetaTrader 4. It has 12 settings, such as Candidate file, Max open slots and Lots per slot. MQL source code included.
Files in the download: LeastCorrelatedSelector.ex4, LeastCorrelatedSelector.mq4, LeastCorrelatedSelector.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Candidate file | SignalCandidates.csv | File under MQL4\Files\ - see .txt for the exact format |
| Max open slots | 3 | Maximum concurrent positions this EA will hold |
| Lots per slot | 0.10 | Fixed lot size per accepted candidate |
| Correlation tf | PERIOD_H1 | Timeframe the correlation return series is built from |
| Correlation bars | 40 | Number of bar-to-bar returns compared per candidate |
| Max allowed correlation | 0.80 | A candidate whose lowest achievable correlation exceeds this is rejected outright |
| Magic number | 20276001 | Magic number identifying this selector's own positions |
| Slippage pips | 5 | Slippage allowance, in pips |
| Check interval seconds | 60 | Seconds between candidate-file re-checks |
| Dry run | false | true = log the selection only, never trades |
| Max retries | 5 | Attempts per order action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Dashboards & Scanners · Buy/Sell Arrows · MT4 Expert Advisor · MQL4 Source Code