Three program types, one language, and why a CFD trader would want a compiled language at all.
Beginner6 min readBeginner → AdvancedLesson 01 / 17
Try it in MetaEditor
Print the contract spec your broker actually offers
Save as MQL5/Scripts/Lesson1ContractSpec.mq5, compile, and drag it onto any chart. Read the output in the Experts tab — every number here is broker-specific, so never hardcode these.
1. Open MetaEditor from MT5 (press F4), and pick the folder this program belongs in — Experts, Indicators, or Scripts.
2. Create a new file, paste this over it, then press F7 to compile. Fix anything the Errors tab reports.
3. Back in MT5, drag it onto a chart — or open the Strategy Tester if it is an Expert Advisor.
Three program types
MQL5 is the language behind MetaTrader 5. Everything you write is one of three things, and which one you pick determines which entry point the terminal calls:
Expert Advisor (EA) — runs continuously, driven by OnTick(). This is your robot.
Custom Indicator — draws on a chart, driven by OnCalculate(). No trading.
Script — runs once and exits, driven by OnStart(). Perfect for one-off checks and for learning.
The folder you save into decides the type: MQL5/Experts/, MQL5/Indicators/, MQL5/Scripts/. Put an EA in the wrong folder and it simply will not be offered where you expect it.
Why bother, when PineScript exists?
Pine is faster to write and lives in the browser. MQL5 is compiled, stricter, and lower-level. You choose MQL5 when you need:
Execution control — exact filling modes, deviation, order types, netting versus hedging.
A real strategy tester — multi-threaded, every-tick modelling, walk-forward, custom optimisation criteria.
Broker independence — your EA runs wherever MT5 runs, with no charting subscription.
Persistence and files — read and write files, call DLLs, talk to the outside world.
The honest caveat
A compiled language will not save a bad idea — it just lets you lose money faster and with more confidence. The hard part of systematic trading is still the idea, the sample size, and the discipline to stop trading a system that has stopped working. MQL5 gives you the machinery; it does not give you an edge.
What you should notice in this lesson's script
Run it on a CFD instrument and read the output. The tick value, contract size, and stops level are the three numbers that decide whether your orders are accepted and how much a stop actually costs you. Almost every beginner bug in Part 3 traces back to ignoring them.
What you just did
Lesson 01 of 17 in MetaTrader 5 MQL5 for CFD Traders. When you have run the examples or read the section, tick it off and move to the next lesson.