Why a Proper MQL5 Environment Matters
Quick answer: To set up MQL5 for MT5, install MetaTrader 5, open MetaEditor, place source files in MQL5/Experts, compile to .ex5, and validate in Strategy Tester before running on Demo/Live.
What you'll complete in this guide:
- Install MT5 and launch MetaEditor correctly
- Understand the MQL5 folder structure and where EAs go
- Compile your first EA and fix common setup errors
- Run your first Strategy Tester check with proper tick mode
Before writing a single line of code, you need a solid development environment. MetaTrader 5 and MetaEditor form the backbone of MQL5 programming — and getting them installed and configured correctly saves hours of troubleshooting later. According to MetaTrader 5's official documentation, the platform is distributed as a web installer that downloads components during setup.
This guide walks you through installing MetaTrader 5, using MetaEditor, understanding the folder structure, compiling your first Expert Advisor, and running it in the Strategy Tester — all based on official MetaQuotes sources.
Related guides: What is an Expert Advisor? · MQL5 Programming Reference · Backtest EA in MT5 Strategy Tester · Build EA Without Coding
Step 1: Download and Install MetaTrader 5
Where to Download
- Official site: metatrader5.com/en/download
- Broker site: Most Forex/CFD brokers offer MT5. Download from your broker for pre-configured server connection.
The installer file is mt5setup.exe — a web installer. Most components are downloaded from the Internet during installation, and the installer selects a server closest to you for faster download.
Installation Requirements
Per MetaTrader 5 Platform Installation:
- OS: Microsoft Windows 2008/7/8/10/11
- Processor: SSE2 support (Pentium 4 / Athlon 64 or higher)
- Other: Depends on use — number of MQL5 apps, charts, instruments
Installation Steps
- Run mt5setup.exe
- Accept the license agreement and click Next
- Click Settings to customize:
- Installation folder — Default is usually
C:\\Program Files\\...\or a broker-specific path - Program group — Name in Start menu
- Open MQL5.community — Optional: open traders' community after install
- Installation folder — Default is usually
- Click Next to start installation, then Finish when done
- Launch MetaTrader 5 from the desktop or Start menu
Tip: To install multiple broker terminals, install each in a different folder (e.g. C:\\MT5-BrokerA\ and C:\\MT5-BrokerB\). Each keeps its own data and settings.
Step 2: Connect to a Trading Account
Before testing EAs, you need market data and a test account:
- File — Open an Account (or use the Account sign-up wizard)
- Choose your broker and create a Demo account (recommended for development)
- Enter login and password; the terminal connects to the server
- Wait for quotes to load — the Market Watch will show symbols
Without an active connection, the Strategy Tester cannot download historical data and testing will fail.
Step 3: Launch MetaEditor
MetaEditor is the integrated development environment for MQL5. It comes with MetaTrader 5 — no separate install.
How to Open MetaEditor
- From MT5: Press F4 or go to Tools — MetaQuotes Language Editor
- From Start menu: Look for "MetaEditor" in the MetaTrader 5 program group
- Direct: Run
metaeditor.exefrom the MT5 installation folder - From Navigator: Right-click an EA/Indicator — Modify — opens source in MetaEditor
MetaEditor Features (Official Documentation)
From MetaEditor Help:
- Syntax highlighting — MQL5 elements highlighted; colors customizable
- Auto-completion — Function names, constants, variables as you type
- MQL Wizard — Generate EA/Indicator templates with event handlers
- Debugging — Step through code, set breakpoints, inspect variables (chart or Strategy Tester)
- Profiling — Measure function execution time for performance tuning
- MQL5 Storage — Version control and cloud backup via MQL5.community
Step 4: Understand the MQL5 Folder Structure
Editable MQL5 files are stored in the Terminal Data Folder, not in Program Files. Per MetaEditor Launch documentation:
- Windows Vista and above:
C:\Users\username\AppData\Roaming\MetaQuotes\Terminal\instance_id\ - Windows XP:
C:\Documents and Settings\username\Application Data\MetaQuotes\Terminal\instance_id\
Open Data Folder: In MetaTrader 5, go to File — Open Data Folder.
Key Directories
| Folder | Purpose |
|---|---|
| MQL5\Experts | Expert Advisors (.mq5 source, .ex5 compiled) |
| MQL5\Indicators | Custom indicators |
| MQL5\Scripts | One-time scripts |
| MQL5\Include | Shared header files (#include) |
| MQL5\Libraries | Shared libraries (.mq5) |
| MQL5\Services | Services (no chart binding) |
EAs must be in Experts to appear in the Navigator under Expert Advisors.
Step 5: Create and Compile Your First EA
Minimal EA Example
Create a new EA in MetaEditor: File — New — Expert Advisor (template). Use this minimal code:
//+------------------------------------------------------------------+
//| MinimalEA.mq5 |
//| Minimal Expert Advisor |
//+------------------------------------------------------------------+
#property copyright "Your Name"
#property link ""
#property version "1.00"
input double LotSize = 0.1;
int OnInit()
{
Print("MinimalEA initialized. Lot size: ", LotSize);
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
Print("MinimalEA removed. Reason: ", reason);
}
void OnTick()
{
// Place your trading logic here
// This example does not open trades — it only runs on each tick
}
Compile the EA
- Save the file as
MinimalEA.mq5in MQL5\Experts - Press F7 (or Compile from the toolbar)
- Check the Toolbox — Errors tab: 0 errors means success
- A
MinimalEA.ex5file is created in the same folder
If you see errors, fix them in the source and recompile. The EA will not appear in MT5 until it compiles without errors.
Step 6: Run the EA in the Strategy Tester
The Strategy Tester lets you backtest EAs on historical data before live trading.
Open the Strategy Tester
- View — Strategy Tester (or Ctrl+R)
- Or right-click an EA in Navigator — Test
Essential Settings
Per Strategy Testing documentation:
| Setting | Description |
|---|---|
| Expert Advisor | Select your EA (e.g. MinimalEA) |
| Symbol | e.g. EURUSD, XAUUSD |
| Period | M1, M5, H1, D1, etc. |
| Date | Start and end of test period |
| Modeling | Tick mode (see below) |
| Deposit | Initial balance (e.g. 10000) |
| Leverage | e.g. 1:100 |
Tick Generation Modes
From official testing docs:
- Every tick — Most accurate, slowest. All ticks simulated.
- Every tick based on real ticks — Uses real broker ticks; first run may take longer to download.
- 1 minute OHLC — Uses Open, High, Low, Close of each minute bar. Good balance of speed and accuracy.
- Open prices only — Fastest, least accurate. Uses only bar open prices.
For most strategies, 1 minute OHLC is a practical choice. Use Every tick for scalping or tick-sensitive logic.
Run the Test
- Click Start in the Strategy Tester
- Watch the Journal and Results tabs
- After completion, review the Graph and Report
Visual mode: Check "Visualization" to see the EA trading on the chart in real time — useful for debugging.
Step 7: Attach an EA to a Chart (Live or Demo)
To run an EA on a live or demo chart:
- Open a chart (e.g. EURUSD, H1)
- In Navigator, expand Expert Advisors
- Drag your EA onto the chart (or double-click)
- In the dialog, configure Inputs (e.g. LotSize) and click OK
- Ensure AutoTrading is enabled (toolbar button should be green; Ctrl+E to toggle)
- Check Tools — Options — Expert Advisors: "Allow Algo Trading" must be checked
The EA will run as long as the chart is open and AutoTrading is on. Check the Experts tab in the Toolbox for messages and errors.
Common Issues and Solutions
EA Does Not Appear in Navigator
- Verify the .mq5 file is in MQL5\Experts
- Compile (F7) and confirm 0 errors
- Right-click Navigator — Refresh
"No enough money" or Trading Disabled
- Enable AutoTrading (Ctrl+E)
- Check Tools — Options — Expert Advisors — Allow Algo Trading
- Ensure the account has sufficient margin
Strategy Tester: "No historical data"
- Connect to your broker and wait for quotes
- Enable the symbol in Market Watch (right-click — Symbols)
- The tester downloads history on first run; it may take a few minutes
Compilation Errors
- Read the error message in the Toolbox
- Common causes: typos, missing semicolons, wrong
#includepath - Use Help — MQL5 Reference in MetaEditor for syntax
Next Steps: Build Your First Trading EA
You now have MetaTrader 5, MetaEditor, and the Strategy Tester ready. In the next tutorial, Build Your First EA, you'll create a Moving Average crossover Expert Advisor from scratch — with real entry/exit rules and full backtesting.
Bonus Tip: Want to skip the setup and build EAs visually? Try AlfaTactix Strategy Builder free — design strategies with indicators, filters, and risk rules in a visual interface, then export production-ready MQL5 in minutes. No MetaEditor or compilation needed. Start building your first EA today.