Keyboard Shortcut (F4)
Press F4 at any time while the MetaTrader 4 or MetaTrader 5 terminal is active. Pressing F4 again switches back to MetaTrader.
MetaQuotes development environment
MetaEditor is the built-in integrated development environment (IDE) and compiler for MetaTrader 4 and MetaTrader 5. It is used to write, edit, compile, debug, and profile MQL4 and MQL5 programs, including Expert Advisors, custom indicators, scripts, and libraries.
Also covering MetaEditor 4, MetaEditor 5, and MQL code compilation workflows.
Getting started
MetaEditor is packaged directly inside MetaTrader installations. You can launch the editor using any of the following five methods.
Press F4 at any time while the MetaTrader 4 or MetaTrader 5 terminal is active. Pressing F4 again switches back to MetaTrader.
In the MetaTrader main menu, click Tools and select "MetaQuotes Language Editor".
Click the IDE icon (resembling a notebook with a pencil and yellow IDE emblem) located on the main toolbar.
Expand Expert Advisors or Indicators in the Navigator pane, right-click any custom program, and click "Modify" to open its source in MetaEditor.
Launch metaeditor64.exe (for MT5) or metaeditor.exe (for MT4) directly from the terminal installation folder or command line.
Version comparison
The target language and terminal matter more than the editor label. MT4 also has object-oriented MQL4, a debugger, profiling, and MQL5 Storage; these are not MT5-only features.
| Feature | MetaEditor 4 (MT4) | MetaEditor 5 (MT5) |
|---|---|---|
| Target platform | MT4; MQL4 source and EX4 executable | MT5; MQL5 source and EX5 executable |
| Language model | Procedural and object-oriented MQL4 | Procedural and object-oriented MQL5; different trading API |
| Debugging and profiling | Built-in debugger and code profiler | Debugger and profiler; real-data and historical-data debugging modes |
| Source storage | Integrated MQL5 Storage is documented for MT4 | MQL5 Storage and project tools; check the installed build |
| Code assistance | Syntax highlighting, completion, definitions and MQL help | Syntax highlighting, completion, definitions and MQL help |
| Output location | Beside the main MQ4 source or project | Beside the main MQ5 source or project |
IDE architecture
MetaEditor is structured into dedicated modular panels for project navigation, code authoring, compilation diagnostics, and performance analysis.
Tree structure organising MQL source directories: Experts (EAs), Indicators, Scripts, Include headers, Libraries, and Projects.
Syntax highlighted editor featuring bracket matching, code folding, auto-formatting, line numbering, and contextual function parameter hints.
Offline documentation accessible by placing the cursor on any MQL keyword or function and pressing F1, providing syntax, signatures, and code examples.
Displays compilation messages, error codes, line numbers, search results, and MQL5 Storage repository sync status.
Set breakpoints in source code, step through execution line by line, inspect local variables, and monitor call stack frames in real time.
Measures execution speed and function call frequencies across historical price data, pinpointing algorithmic bottlenecks.
Step-by-step guide
Follow this five-step walkthrough to create, code, compile, and execute your first automated program in MetaTrader 5.
Press F4 in MetaTrader to launch MetaEditor. Click "New" (or Ctrl+N) to open the MQL Wizard, which generates boilerplate structure.
For this EA workflow, select an Expert Advisor template. Indicators use OnCalculate and scripts use OnStart; they do not follow the OnTick workflow below.
Specify input parameters (such as lot size or moving average period) and select event handlers (OnInit, OnTick, OnTimer, OnDeinit).
Add your trading calculations inside OnTick(). Press F7 to compile. Inspect the Errors tab to verify 0 errors and 0 warnings.
Switch back to MetaTrader (F4). Test the EA in the Strategy Tester first, then attach it to a demo chart and inspect its logs and order behavior.
F7 diagnostics appear in the Toolbox Errors tab. Runtime failures, such as an array index out of range, require a test run and inspection of the terminal or tester logs.
undeclared identifier '...' Root Cause
Variable or function name is misspelled or used before being declared in scope.
Solution
Declare the variable type (such as double, int, or string) before usage, or check header includes.
implicit conversion from '...' to '...'Root Cause
Assigning incompatible data types without explicit type casting (such as string to number).
Solution
Use explicit conversion functions like StringToDouble(), DoubleToString(), or IntegerToString().
array out of range (runtime)Root Cause
Accessing an array index that exceeds its allocated element size or history buffer limit.
Solution
Verify ArraySize() or use ArrayResize(), and check buffer index boundaries inside calculation loops.
unresolved function call '...'Root Cause
Calling a function whose declaration or library header is missing from the file.
Solution
Verify #include directives and ensure required .mqh header files reside in the MQL4/Include or MQL5/Include directory.
Pineify AI Coding Agents
MetaEditor compiles source for the target terminal. Pineify MQL4 and MQL5 AI Coding Agents can draft editable source from a written specification. Inspect the returned diagnostics; a draft is not a guarantee of compilation or correct execution.
Recommended 4-Step Development Cycle
Generate and revise editable MQL5 Expert Advisors, custom indicators, and scripts.
Create single-file MT4 Expert Advisors and indicators from natural language prompts.
Automate lot sizing, trailing stops, break-even, and partial exits on MT4 and MT5.
Browse MetaTrader 5 code tutorials, indicator guides, and testing frameworks.
Triage and resolve common MetaEditor compiler, runtime, and trade server errors.
Understand MT5 broker licensing, hosting architecture, APIs, and infrastructure scope.
This page provides technical software development and educational reference material, not financial or investment advice. Always test trading algorithms in a demo environment before connecting to live broker accounts.