Lesson 4. MT5 Architecture for EAs — What Beginners Must Know
Understand how MT5 "holds" a robot: terminal/account/symbol, netting vs hedging, global AutoTrading vs chart-level attachment, magic numbers, inputs, logs/permissions, and multi-chart behavior.
You chose a robot style. Now learn how MT5 actually runs an EA, so you avoid common pitfalls.
4.1. Big Picture: Terminal → Account → Chart → EA
Understand the hierarchy before attaching any robot.
- •Terminal: the MT5 app runs your accounts, charts, and EAs.
- •Account: login to a broker server (demo/live), with its own mode (netting/hedging) and permissions.
- •Symbol + Timeframe: each chart is a 'view' of one symbol on one timeframe.
- •EA on chart: each EA instance runs on a specific chart and timeframe; it listens to ticks and timer events there.
4.2. Netting vs Hedging (Quick Refresher Applied to EAs)
One net position per symbol; opposite trades reduce/increase the single position. EA should manage partial closes by sending opposite orders.
Separate long and short positions; EA must track multiple tickets and manage SL/TP per position.
4.3. AutoTrading, Chart Attachment, and Scope
Global AutoTrading button (toolbar)
Master switch — OFF stops all EAs from trading; ON allows EAs to trade (if chart-level permissions also allow it).
Chart-level
When attaching an EA (Navigator → Expert Advisors → drag to chart), allow "Algo trading" in the EA settings dialog; the EA runs only on that chart's symbol/timeframe.
Remove/disable per chart
Right-click chart → Expert List → remove; or uncheck "Algo trading" for that EA.
4.4. Magic Number and Inputs (Distinct Instances)
4.5. Logs, Journals, Experts, and Permissions (Debug Basics)
Terminal/Toolbox → Journal
Terminal-level messages (connection, orders, errors).
Terminal/Toolbox → Experts
EA-specific messages (print logs, order results, errors like "Trade disabled" or "Invalid stops").
"AutoTrading disabled"→ Turn on global/EA switch."Trade is not allowed"→ Permissions in EA settings, markets closed, symbol trade disabled."Invalid stops"→ SL/TP too close to price (check symbol's stop level)."No prices / Market closed"→ Trying to trade outside hours or no ticks.4.6. Symbols, Timeframes, and Multi-Chart Behavior
- •Each EA instance is bound to its chart's symbol/timeframe; it won't trade other symbols unless coded for it.
- •Multi-symbol EAs exist, but standard EAs watch only their chart's symbol.
- •More charts/EAs = more CPU. Close unused charts.
- •Restart behavior: when MT5 restarts, attached EAs re-load with previous inputs if AutoTrading is on and permissions allow it.
4.7. Practice: Attach an EA Twice with Unique Magic Numbers
Practice — 10–15 min
4.8. Quick Diagnostics Checklist
- 1.Global AutoTrading ON?
- 2.EA settings "Allow Algo trading" ON?
- 3.Correct account mode for the EA logic (netting/hedging)?
- 4.Unique magic numbers per instance?
- 5.Logs show errors? (Journal/Experts)
- 6.SL/TP not violating minimum stop levels?
- 7.Market open? Symbol trading allowed?
Lesson 4 Quiz
Test your understanding with 3 questions. Pass with 2/3 correct.
What's Next?
You understand how MT5 hosts an EA — hierarchy, permissions, magic numbers, and logs. Next, we'll do the hands-on: install a real EA, configure it, and launch it on a demo chart.
Next: Install & Basic Configure an EA