P
PipsGrowth
Back to Auto Trading Hub
MT5 / MQL5 track

MT5 Expert Advisors Guide

How EAs work in MT5, what inputs matter, and how to test them with realistic execution assumptions.

Risk warning

Educational content only. Automated trading can lose money quickly. Backtests do not guarantee live results, and every bot should be demo-tested with realistic spread, commission, slippage, and news conditions before any live use. This is not financial advice.

Role of this page

MT5 Expert Advisors are not the same product as Python bots. An EA is an MQL5 program that lives inside MetaTrader, reacts to terminal events, and must respect broker symbol settings before every order.

Who this is for

  • MQL5 EAs that must run inside MetaTrader 5 on a broker account or VPS.
  • Strategies needing MT5 Strategy Tester, optimization, forward testing, and terminal logs.

Not for

  • Python-only API trading systems that do not use the MT5 terminal.
  • Order-flow assumptions when the broker does not provide reliable Depth of Market.

EA building blocks

An EA should separate signal logic, risk sizing, execution, trade management, and safety checks. MT5 testing and optimization can evaluate input variables, custom criteria, and forward testing, but live results still depend on broker execution.

  • Use input parameters for optimizable settings.
  • Use CTrade-style execution wrappers and check return codes.
  • DOM/order book logic is optional and broker-dependent.

Practical examples

  • Native EA: OnInit validates symbol specs; OnTick evaluates rules; risk gate checks spread/margin; CTrade sends order; logs record every rejection.
  • Hybrid only when justified: Python researches parameters offline, then exports approved settings to the EA. Python does not randomly override live orders.

Checklist

  • Inputs: symbol, magic number, lot model, stop model, session window, spread/slippage caps.
  • Execution: fill policy, trade return codes, retry rules, partial close support, hedge/netting account type.
  • Logging: signal state, rejected-trade reason, order ticket, spread, slippage, and modification result.

Validation plan

  • Run MT5 backtests with realistic spread/commission and compare fixed spread versus variable spread behavior.
  • Use forward optimization periods and demo logs to check tester-to-live differences.

Implementation notes

  • Keep OnTick signal evaluation separate from order execution and risk gates.
  • Use OnTester or custom criteria only after the baseline logic is stable.

Developer / IDE prompt

Generate an MQL5 EA plan only. Include inputs, OnInit checks, OnTick flow, CTrade execution checks, stop/freeze-level handling, tester settings, optimization ranges, forward-test plan, and all no-trade filters. Do not add Python unless explicitly requested as an external research layer.

Next step

Turn these concepts into a complete bot logic plan with the strategy builder wizard.

Open Strategy Builder
MT5 Expert Advisors Guide