MetaTrader 5 MQL5 for CFD Traders
Write indicators, Expert Advisors, and risk-managed automation — MQL5 from zero to a complete trading robot.
About this course
MQL5 is MetaTrader 5's C-style language. It is stricter and lower-level than PineScript, but it buys you something Pine cannot: full control over order execution, position management, and a built-in multi-threaded strategy tester. This course takes you from opening MetaEditor to shipping a complete trend-following Expert Advisor that sizes by risk, validates every order against the broker's own limits, and cleans up after itself. Along the way you will hit the CFD-specific traps that break most first robots — tick value versus point, minimum stop distance, filling modes, and swap.
What you'll be able to do
- Write MQL5 indicators, scripts, and Expert Advisors from scratch
- Place and manage orders correctly, including filling modes and stop validation
- Size positions from tick value and contract size instead of guessing lots
- Read a Strategy Tester report and spot an overfitted backtest
- Build a multi-timeframe EA with proper handle cleanup
Prerequisites
- MetaTrader 5 installed (any broker, demo account is fine) — MetaEditor ships with it
- Basic chart reading: candles, support/resistance, moving averages
- Part 1 assumes no prior coding, but MQL5 is stricter than Pine — expect to think about types
Learning path
4 parts · 17 lessons · every lesson ships with a complete MetaEditor program you can paste in and run.
Part 1MQL5 Foundations
Set up MetaEditor, learn the event model, and draw your first indicator on the chart.
5 done
MQL5 Foundations
Set up MetaEditor, learn the event model, and draw your first indicator on the chart.
- 01Beginner6 min
What MQL5 Is (and What It Is Not)
Three program types, one language, and why a CFD trader would want a compiled language at all.
- 02Beginner7 min
Program Structure and the Event Model
OnInit, OnTick, OnDeinit, OnCalculate — MQL5 does not run top to bottom. It waits for events.
- 03Beginner8 min
Data Types, Variables, and Strict Typing
MQL5 will not silently convert types the way Pine does. Know your ints from your doubles.
- 04Beginner9 min
Your First Indicator: A Moving Average
Indicator buffers, OnCalculate, and why the very first bars of every indicator are empty.
- 05Beginner7 min
Inputs, Parameters, and the Strategy Tester
Turn magic numbers into inputs, group them, and let the tester search for values instead of you.
Part 2Logic and Reuse
Conditions, loops, functions, and the data structures MQL5 hands you.
4 done
Logic and Reuse
Conditions, loops, functions, and the data structures MQL5 hands you.
- 01Beginner7 min
Conditional Logic and Operators
if/else, switch, and the pre-trade gate that stops bad orders before the broker does.
- 02Beginner8 min
Loops: Scanning Bars Efficiently
for and while, plus the two guards that keep a loop from hanging the terminal.
- 03Intermediate9 min
Functions, Includes, and the Standard Library
Stop repeating yourself. Meet CTrade, the class that saves you fifty lines of boilerplate.
- 04Intermediate10 min
Arrays, Structures, and Objects
MqlRates, MqlTradeRequest, dynamic arrays, and just enough OOP to read the standard library.
Part 3Expert Advisors
Send real orders, handle rejections, size by risk, and read a backtest honestly.
4 done
Expert Advisors
Send real orders, handle rejections, size by risk, and read a backtest honestly.
- 01Intermediate10 min
From Indicator to Expert Advisor
The EA skeleton: new-bar gate, position check, magic number, and one clean entry.
- 02Intermediate12 min
Placing and Managing Orders
MqlTradeRequest by hand: filling modes, deviation, retcodes, and closing what you opened.
- 03Intermediate11 min
Reading a Backtest Without Fooling Yourself
Profit factor, drawdown, expected payoff, trade count — and how to spot a curve-fit.
- 04Advanced13 min
Position Sizing for CFD (The Lesson Most EAs Skip)
Lots are not risk. Convert tick value, contract size, and stop distance into a real position size.
Part 4Advanced Patterns
Indicator handles, multi-timeframe context, automation, and the complete EA.
4 done
Advanced Patterns
Indicator handles, multi-timeframe context, automation, and the complete EA.
- 01Intermediate11 min
Built-In Indicators via Handles
Stop hand-rolling averages. Create handles, read them with CopyBuffer, release them on exit.
- 02Advanced12 min
Multi-Timeframe and Multi-Symbol
Read a higher timeframe for regime, scan other symbols, and avoid the repainting trap.
- 03Advanced10 min
Timers, Events, and Alerts
OnTimer, OnTrade, OnChartEvent, and pushing a notification to your phone.
- 04Advanced15 min
The Complete Expert Advisor
Everything in one EA: regime filter, ATR stops, risk sizing, validation, and clean shutdown.
Ready to run your first MetaEditor program?
Jump into lesson 1 — setting up the MetaEditor editor and writing your first program. No prior coding required.
Continue with another course
TradingView PineScript for CFD Traders
From Pine v5 basics to a complete trend-following system — 17 lessons, 4 parts.
17 lessonsMacroeconomic Data Analysis for CFD Traders
From reading the calendar to a complete weekly macro workflow — 17 lessons, 4 parts.
17 lessonsGold Analysis for CFD Traders
From the four drivers to a complete weekly gold workflow — 17 lessons, 4 parts.
17 lessonsTechnical Indicators for Beginners
From 'what is an indicator' to a two-indicator setup you can actually defend — 12 lessons, 3 parts.
12 lessonsCandlestick Charting for Beginners
From 'what is a candle' to reading patterns in context — 12 lessons, 3 parts, with a diagram in every one.
12 lessonsPattern Trading for Beginners
From support and resistance to a complete pattern trade plan — 14 lessons, 4 parts, 20 diagrams.
14 lessonsPair this with execution
Compare brokers
Execution engine matters as much as the script. Look at latency, API stability, and product structure side by side.
OpenTradingView strategies
See how other traders translate ideas into Pine. Useful as reference implementations while you build your own.
OpenKnowledge base
Broader CFD curriculum — leverage, edge-building, and systematisation — separate from this course.
Open