Lead Lag Follower System
Lead-lag structure between related instruments (a major index and a correlated FX pair, two commodity-linked currencies, a metal and its miner-heavy currency) is a real, measurable statistical property, but most "follow the leader" scripts either hardcode a lag of one bar or skip measurement entirely and just assume correlation exists. This EA measures it properly: for every lag from 1 to InpMaxLag bars it computes the Pearson correlation between the leader's return at t-lag and the follower's return at t, over a rolling InpCorrWindow-bar sample, and keeps whichever lag produced the strongest |correlation|. A trade only fires when two conditions are both true: the best lag's correlation clears InpMinCorrelation, and the leader's most recent 1-bar move clears InpMoveThresholdPips. The follower is then traded in the direction the correlation sign implies - same direction as the leader on positive correlation, opposite direction on negative correlation. The position carries a decay-aware exit: it is flattened after the same number of bars as the lag it was opened on, regardless of P/L. A lead-lag relationship measured on a rolling window is a statistical tendency over a specific number of bars, not a standing law - once that many bars have passed, the "follow window" this particular signal was based on has already closed, so holding the position longer is holding on hope rather than on the measured effect. Notes and limitations - Correlation and lag are re-measured every closed bar from a rolling window - they can and do change over time, and a leader that worked last month can stop working. - One position at a time on the follower, tracked by InpMagicNumber. - The decay-exit lag is remembered only for the life of the running EA instance; if the terminal restarts with a position already open, the lag used to size the decay exit is lost and the position is left to its fixed stop/target only. - Both the leader and follower symbol need enough visible chart history for InpCorrWindow + InpMaxLag bars; a freshly added leader symbol may need its history to finish downloading first. - No slippage or spread filter beyond the standard retry/slippage controls - illiquid leader symbols can produce noisy correlation readings.
Expert advisor · MT4 · v1.0 · Free
About Lead Lag Follower System
Lead Lag Follower System is an expert advisor (trading robot) for MetaTrader 4. It has 12 settings, such as Leader symbol, Corr window and Max lag. MQL source code included.
Files in the download: LeadLagFollowerSystem.ex4, LeadLagFollowerSystem.mq4, LeadLagFollowerSystem.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 |
|---|---|---|
| Leader symbol | EURUSD | Leader symbol (follower is this chart's own symbol) |
| Corr window | 120 | Bars used to measure correlation at each lag |
| Max lag | 10 | Largest lag tested, in bars |
| Min correlation | 0.35 | Minimum |correlation| at the best lag to trust the signal |
| Move threshold pips | 15.0 | Minimum leader 1-bar move, in pips, required to trigger |
| Stop loss pips | 40 | Stop loss distance, in pips (0 = none) |
| Take profit pips | 0 | Take profit distance, in pips (0 = none - decay exit only) |
| Fixed lots | 0.10 | Fixed lot size |
| Magic number | 20260351 | 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: Buy/Sell Arrows · MT4 Expert Advisor · MQL4 Source Code