Loading…

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

SettingDefaultWhat it does
Leader symbolEURUSDLeader symbol (follower is this chart's own symbol)
Corr window120Bars used to measure correlation at each lag
Max lag10Largest lag tested, in bars
Min correlation0.35Minimum |correlation| at the best lag to trust the signal
Move threshold pips15.0Minimum leader 1-bar move, in pips, required to trigger
Stop loss pips40Stop loss distance, in pips (0 = none)
Take profit pips0Take profit distance, in pips (0 = none - decay exit only)
Fixed lots0.10Fixed lot size
Magic number20260351Magic 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: Buy/Sell Arrows · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria