Correlated Entry Blocker
Opening a long on EURUSD while already long GBPUSD looks like two trades but, when the pair is trading at 0.9 correlation, is close to one trade at double size. The reverse trap is just as common: a short USDCHF and a long EURUSD look like opposite bets but express the same view on the dollar because EURUSD and USDCHF are negatively correlated. Both cases pass a naive "one position per symbol" check without catching the real problem, which is directional exposure, not symbol count. Before every entry this EA scans the account's other open positions. For each one on a symbol from the configured watch list, it computes a fresh Pearson correlation between that symbol and the chart symbol over a rolling lookback - recomputed on every check, never cached, because correlation between two instruments drifts and a stale reading is exactly what causes both false blocks and false approvals. If the |correlation| clears the configured threshold, the existing position's direction is combined with the correlation's sign to work out the directional view it already expresses on the chart symbol; if that matches the new signal's direction, the entry is rejected and the reason is logged. The entry signal itself is a plain fast/slow EMA crossover, deliberately unremarkable - the filter is the point, not the signal it is attached to. Swap EvaluateSignal() for any other entry logic and the blocking behaviour carries over unchanged. Notes and limitations - Only positions on symbols listed in InpWatchSymbols are considered; an unlisted correlated symbol will not block anything. - Correlation is computed from historical closes, which is a backward- looking estimate - a genuine regime change in the relationship between two symbols will only show up after enough new bars have accumulated to move the rolling window. - Only open positions are checked; pending orders on correlated symbols are not counted as existing exposure (MQL4 market orders / MQL5 positions only - MQL5 pending orders live in a separate pool and are not read by this EA, matching the MQL4 version's own scope). - The blocker only ever prevents a new entry - it never closes or modifies an existing position. - Requires AutoTrading enabled. MQL4 checks IsTradeAllowed(); MQL5 checks TERMINAL_TRADE_ALLOWED, ACCOUNT_TRADE_ALLOWED and ACCOUNT_TRADE_EXPERT, since MQL5 has no single equivalent call.
Expert advisor · MT4 · v1.0 · Free
About Correlated Entry Blocker
Correlated Entry Blocker is an expert advisor (trading robot) for MetaTrader 4 based on Moving Average. It has 12 settings, such as Watch symbols, Corr period and Min correlation. MQL source code included.
Files in the download: CorrelatedEntryBlocker.ex4, CorrelatedEntryBlocker.mq4, CorrelatedEntryBlocker.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 |
|---|---|---|
| Watch symbols | GBPUSD,USDCHF,AUDUSD | Comma-separated symbols checked for correlated positions |
| Corr period | 100 | Bars used for the rolling correlation calculation |
| Min correlation | 0.70 | |correlation| at/above which two symbols count as expressing the same view |
| Fast ma period | 10 | Fast MA period for the entry signal |
| Slow ma period | 30 | Slow MA period for the entry signal |
| Stop loss pips | 30 | Stop loss per trade, in pips |
| Take profit pips | 45 | Take profit per trade, in pips (0 = none) |
| Lots | 0.01 | Fixed lot size per entry |
| Magic number | 20260830 | Magic number for orders opened by this EA |
| Slippage pips | 3 | Slippage tolerance, in pips |
| Max retries | 5 | Attempts per trade 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: Moving Average · Buy/Sell Arrows · EURUSD · GBPUSD · MT4 Expert Advisor · MQL4 Source Code