MT5 Lab

MetaTrader 5 and MQL5: A Practical Beginner's Guide to Systematic Trading

Learn what MetaTrader 5, MQL5, Expert Advisors, and Strategy Tester do, then follow a risk-aware workflow from a trading rule to a reproducible demo test.

한국어 원문 읽기

Key takeaways

MetaTrader 5 brings charts, order management, MQL5 development, automated execution, and strategy testing into one desktop platform.

MQL5 is the programming language used to build Expert Advisors, indicators, scripts, and other tools for MT5.

A responsible workflow moves from an explicit rule to compilation, backtesting, forward testing on demo, and monitored deployment; none of those stages guarantees a profit.

MetaTrader 5 and MQL5: a practical starting point

Three key takeaways

  • MetaTrader 5 is the terminal; MQL5 is the language used to create programs that run inside it.
  • Your first useful milestone is not a profitable robot. It is a rule you can compile, run, observe, and reproduce.
  • Backtests and demo results are evidence about a specific setup, not promises about future returns or live execution.

Algorithmic trading is often marketed as if the difficult part were finding a clever indicator or adding AI. In practice, the foundation is less glamorous: define an unambiguous rule, encode it without changing its meaning, test it under recorded assumptions, and inspect every failure.

MetaTrader 5 (MT5) and MQL5 support that workflow in one ecosystem. The official MetaTrader 5 download page opens in a new tab provides desktop, web, and mobile access, but the desktop terminal is the relevant environment for writing an Expert Advisor and using Strategy Tester.

This guide explains the toolchain before you write your first trading program. It is broker-neutral: available markets, symbols, trading costs, account rules, and even some interface labels depend on the broker and jurisdiction you use.

MT5, MQL5, and an EA are different things

The names appear together so often that beginners understandably treat them as one product. Separating them makes the rest of the workflow easier to reason about.

TermWhat it isWhat you use it for
MetaTrader 5A trading terminal and execution environmentView markets, manage charts and orders, run programs, and test strategies
MetaEditorThe development environment bundled with desktop MT5Write, compile, and debug MQL5 source code
MQL5A C++-style language designed for the MetaTrader ecosystemExpress signals, risk rules, order logic, indicators, and utilities
Expert Advisor (EA)An MQL5 program attached to a chart or run in Strategy TesterEvaluate rules repeatedly and, when permitted, send or manage orders
Strategy TesterMT5's historical simulation and optimization toolReplay an EA against historical data and inspect its behavior

MetaQuotes describes the platform's algorithmic-trading stack as an integrated combination of MetaEditor, MQL5, Expert Advisors, and Strategy Tester. The official algorithmic trading overview opens in a new tab is a useful map of those components.

What can you build with MQL5?

The MQL5 language reference opens in a new tab documents several program types. They share a language but have different lifecycles and permissions.

Program typeTypical jobSensible first use
Expert AdvisorReact to ticks or events and optionally place tradesLog one clearly defined signal on a demo chart
Custom IndicatorCalculate and draw analytical valuesVisualize a signal before automating an order
ScriptRun a task once and exitPrint symbol information or export a snapshot
ServiceRun independently of a chartAdvanced data or integration tasks
Library / include filePackage reusable logicSeparate risk and order code as a project grows

A beginner does not need machine learning, a paid signal, or a complex indicator stack. A deterministic rule such as “evaluate the previous completed candle once per new bar” is enough to learn program state, data access, compilation, logs, and test controls.

The workflow that makes a test reproducible

Treat an EA as an experiment rather than an answer. Each stage should produce something another person—or your future self—can inspect.

StageDeliverableQuestion to answer before moving on
1. SpecifyPlain-language entry, exit, sizing, and failure rulesCould two developers implement the same behavior from this specification?
2. ImplementVersioned .mq5 sourceDoes the code match the rule, including edge cases?
3. CompileAn .ex5 file with zero compiler errorsDid the intended source file compile in the recorded MT5 build?
4. BacktestSettings, report, logs, and test datesDoes order behavior make sense before looking at net profit?
5. Forward-testDemo logs across unseen market dataDo spread, session, and connection conditions expose new failures?
6. Deploy cautiouslyMonitoring and stop proceduresCan you disable the EA and reconcile its positions when something goes wrong?

A compiler success only proves that the source is syntactically acceptable. A profitable backtest only describes one historical simulation. A clean demo run still cannot reproduce live liquidity, slippage, latency, or the psychological consequences of real losses.

Install the desktop toolchain

  1. Download desktop MT5 from MetaQuotes or from the regulated broker you have independently selected.
  2. Open a demo account appropriate for your location. Do not fund an account just to complete this tutorial.
  3. In MT5, use Help → About to record the terminal build and architecture.
  4. Press F4 to open MetaEditor.
  5. Press Ctrl+R in MT5 to confirm that Strategy Tester opens.
  6. In Market Watch, open the specification for the symbol you intend to test and record its contract size, volume step, stop level, trading sessions, and displayed spread.

The terminal may show broker-specific symbol suffixes such as .a, -pro, or another naming convention. Do not assume that a symbol called EURUSD, XAUUSD, or an index alias has identical contract specifications across accounts.

Learn the smallest code-to-log loop first

Before an EA can send an order, prove that you can create, compile, and observe a harmless program. In MetaEditor, create a new Script, replace the template with the code below, and compile it with F7.

void OnStart()
  {
   Print("Hello from MQL5 on ", _Symbol);
  }

Run the script from MT5's Navigator and look for the message in the Experts or Journal log. This establishes a compact feedback loop:

  1. edit source;
  2. compile;
  3. run in the terminal;
  4. inspect the log;
  5. change one thing and repeat.

The official MetaEditor and automated-trading help opens in a new tab explains how MQL5 programs are created, compiled, debugged, and run in the platform.

Turn trading language into testable rules

“Buy in an uptrend” is an idea, not a specification. A program needs definitions for the observation time, data source, order action, position sizing, and exceptional cases.

Vague phraseQuestions that make it testable
Buy in an uptrendWhich timeframe? Which completed bar? Which indicator and exact threshold?
Use a small positionFixed volume or percentage risk? What if the requested volume violates the symbol's minimum or step?
Add a stop lossPoints, pips, price, or account currency? What if the broker's minimum stop distance is larger?
Trade onceOnce per tick, bar, day, signal transition, or open position?
Exit when conditions changeEvaluate intrabar or only at a completed-bar boundary? What happens if closing fails?

A deliberately simple learning rule might be:

  • evaluate only when a new bar begins;
  • read the previous completed candle;
  • request one direction based on that candle;
  • allow no more than one position for the symbol;
  • attach explicit stop-loss and take-profit requests;
  • log every rejected trade request with its return code.

That is not a recommended strategy. It is a compact system for learning the mechanics in the next hands-on guide.

Record the environment, not just the result

An MT5 result without its inputs is difficult to reproduce. Keep this record beside each test:

FieldExample of what to record
TerminalMT5 build number, operating system, 32/64-bit architecture
AccountDemo/live status, account currency, netting or hedging mode, leverage shown by the account
InstrumentExact broker symbol, contract specification, commission, swap, session, and volume rules
DataDate range, timeframe, modeling mode, data quality notes
EASource version or checksum, input preset, magic number
ExecutionSpread setting, latency assumptions, rejected-order logs
EvaluationNet profit, drawdown, trade count, costs, and known anomalies

Two tests that use the same strategy name but different symbol specifications or data ranges are different experiments.

What systematic execution improves—and what it does not

Code can apply a defined rule consistently, create an audit trail, and expose assumptions to testing. Those are valuable benefits. Code cannot make a weak premise profitable, prevent regime changes, guarantee fills, repair bad data, or remove operational risk.

Particular risks include:

  • overfitting: tuning parameters until they explain historical noise;
  • look-ahead bias: accidentally using information that was unavailable at decision time;
  • cost blindness: omitting spread, commission, swap, and slippage;
  • execution mismatch: assuming demo and live fills behave identically;
  • automation risk: repeating a coding or configuration mistake faster than a human would;
  • leverage risk: losing more quickly when a product amplifies price movements.

Before any live use, you should be able to explain the EA's position-sizing ceiling, stop procedure, reconnection behavior, duplicate-order protection, and ownership of existing positions. If you cannot, the system is not operationally ready.

A practical readiness checklist

You are ready for the first EA exercise when you can confirm all of the following:

  • [ ] Desktop MT5 and MetaEditor open normally.
  • [ ] You are signed in to a demo account.
  • [ ] You know where Navigator, Market Watch, Toolbox, Experts, and Journal are.
  • [ ] A harmless script compiles and produces a visible log message.
  • [ ] Strategy Tester opens, even if you have not run a test yet.
  • [ ] You have recorded the exact symbol specification and terminal build.
  • [ ] You understand that enabling Algo Trading grants execution permission; it does not validate the EA.

Up next

Next, build and attach your first MQL5 Expert Advisor on an MT5 demo account. You will download the complete source, compile it, inspect its limitations, attach it to a chart, and use the Experts and Journal logs as the success criteria—not profit.