Loading…

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 · MT5 · v1.0 · Free

About Least Correlated Candidate Selector

Least Correlated Candidate Selector is an expert advisor (trading robot) for MetaTrader 5. It has 12 settings, such as Candidate file, Max open slots and Lots per slot. MQL source code included.

Files in the download: LeastCorrelatedSelector.ex5, LeastCorrelatedSelector.mq5, LeastCorrelatedSelector.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Candidate fileSignalCandidates.csvFile under MQL5\Files\ - see .txt for the exact format
Max open slots3Maximum concurrent positions this EA will hold
Lots per slot0.10Fixed lot size per accepted candidate
Correlation tfPERIOD_H1Timeframe the correlation return series is built from
Correlation bars40Number of bar-to-bar returns compared per candidate
Max allowed correlation0.80A candidate whose lowest achievable correlation exceeds this is rejected outright
Magic number20276001Magic number identifying this selector's own positions
Slippage pips5Slippage allowance, in pips
Check interval seconds60Seconds between candidate-file re-checks
Dry runfalsetrue = log the selection only, never trades
Max retries5Attempts per order action before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Dashboards & Scanners · Buy/Sell Arrows · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria