Loading…

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

SettingDefaultWhat it does
Watch symbolsGBPUSD,USDCHF,AUDUSDComma-separated symbols checked for correlated positions
Corr period100Bars used for the rolling correlation calculation
Min correlation0.70|correlation| at/above which two symbols count as expressing the same view
Fast ma period10Fast MA period for the entry signal
Slow ma period30Slow MA period for the entry signal
Stop loss pips30Stop loss per trade, in pips
Take profit pips45Take profit per trade, in pips (0 = none)
Lots0.01Fixed lot size per entry
Magic number20260830Magic number for orders opened by this EA
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per trade 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 4 open File → Open Data Folder, then go to MQL4 → Experts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 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: Moving Average · Buy/Sell Arrows · EURUSD · GBPUSD · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria