# MT5 Bar Sync Lag Study — Findings

**Study:** `study_bar_timing`  
**Primary:** EURUSD M15  &nbsp;|&nbsp; **Secondaries:** GBPUSD, USDCHF, USDCAD, GBPJPY, EURJPY, EURAUD  
**Period:** 2025-05-08 → 2026-05-08 &nbsp;(24 751 M15 bars)  
**Status:** ✅ Complete

---

## What we measured

When a multi-symbol EA runs on EURUSD as the primary chart, does `iTime(secondary, tf, 0)`
return a stale (previous) bar time at the moment `OnTick` fires for the primary new-bar event?

We measured the **lag in ticks** — how many ticks after the primary new-bar event until
each secondary symbol's bar time advanced — across four MT5 modelling modes.

**Lag metric — `lagged_pct`:** % of M15 bars where the secondary was NOT yet on the
current bar when the primary fired. Includes both within-window lags (caught up late)
and window-exceeded cases (never caught up = 1-bar late in Open Prices Only mode).

---

## Results

| Symbol | Every Tick (M=0) | Real Ticks (M=4) | 1-Min OHLC (M=1) | Open Prices Only (M=2) |
|--------|:---:|:---:|:---:|:---:|
| GBPUSD | ~99.7% | ~99.7% | ~99.7% | ~100% |
| USDCHF | ~99.8% | ~99.8% | ~99.8% | ~100% |
| USDCAD | ~99.7% | ~99.7% | ~99.7% | ~100% |
| GBPJPY | ~99.6% | ~99.6% | ~99.6% | ~100% |
| EURJPY | ~0.6% | ~0.6% | ~0.6% | ~0% |
| EURAUD | ~0.7% | ~0.7% | ~0.7% | ~0% |

---

## Key findings

### 1 — Non-EUR pairs lag on virtually every bar
GBPUSD, USDCHF, USDCAD, and GBPJPY show `iTime()` lag on **~99.7% of M15 bars**,
consistently across Every Tick, Real Ticks, and 1-Min OHLC modes.
The lag is almost always exactly **1 tick**.

### 2 — Real Ticks matches Every Tick
Model=4 (real tick data) produces the same lag pattern as Model=0 (synthesized ticks).
The behaviour is a structural property of how MT5 advances off-chart bars, not an
artefact of tick synthesis.

### 3 — Open Prices Only has the most severe practical impact
With only 1 tick per bar, the secondary bar **never** has a chance to catch up within
the tracking window. `lagged_pct ≈ 100%` for all non-EUR pairs, expressed entirely as
window-exceeded (lag = −1). Since there are no more ticks in this bar period, the
secondary `iTime()` will only reflect the new bar on the **next** M15 bar tick —
a systematic **+15-minute delay**.

This directly explains the +15-minute entry delays observed in the portfolio EA,
which was running under Open Prices Only.

### 4 — EUR pairs are nearly unaffected
EURJPY and EURAUD lag on fewer than **1% of bars** across all tick-based models and
show **0% lag** in Open Prices Only mode. MT5 appears to advance EUR-based bar times
simultaneously with EURUSD, consistent with shared exchange-session boundaries.

### 5 — The EUR/non-EUR split is stable across all models
The split is not an artefact of any single modelling choice.
Every Tick, Real Ticks, 1-Min OHLC, and Open Prices Only all show the same pattern.

---

## Root cause

MT5 strategy tester advances off-chart bar timestamps on a **per-symbol tick delivery
schedule**, not all at once. When the primary symbol receives its first tick of a new bar,
secondary symbols with independent tick streams (non-EUR pairs vs EURUSD) have not yet
received their corresponding tick, so `iTime()` still returns the old bar. In models with
multiple ticks per bar this resolves within 1 tick. In Open Prices Only (1 tick per bar)
it never resolves within the bar.

---

## Recommended architecture

| Pattern | Assessment |
|---------|-----------|
| Single EA, multi-symbol, reads `iTime()` off-chart | **Avoid in Open Prices Only** — produces systematic +1-bar entry delay for non-EUR pairs |
| Gate off-chart reads: `if iTime(sym, tf, 0) == current_bar` | Eliminates stale reads in tick models; **does not help** in Open Prices Only |
| Independent per-symbol backtests + external schedule merge | **Recommended** — no off-chart dependency |

---

## Reproducibility

```
# Install: pip install pandas numpy matplotlib
cd study_bar_timing/python
python run_backtests.py          # runs all 4 models (~2–5 min each)
python analyze_timing.py         # generates report.md + 3 charts
```

Output in `results/`:
- `report.md` — full statistics and verdict
- `lag_heatmap.png` — colour-coded lag prevalence grid
- `lag_overview.png` — grouped bar chart (symbols × models)
- `lag_distributions.png` — within-window tick histogram (tick models)

EA source: `mql5/BarTimingProbe/BarTimingProbe.mq5`  
INI files: `ini/probe_*.ini`
