MetaQuotes development environment

MetaEditor: The Complete Guide to MT4 & MT5 Code Development

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

How to Open MetaEditor in MT5 and MT4

MetaEditor is packaged directly inside MetaTrader installations. You can launch the editor using any of the following five methods.

1

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.

2

Top Menu Navigation

In the MetaTrader main menu, click Tools and select "MetaQuotes Language Editor".

3

Standard Toolbar Icon

Click the IDE icon (resembling a notebook with a pencil and yellow IDE emblem) located on the main toolbar.

4

Navigator Context Menu

Expand Expert Advisors or Indicators in the Navigator pane, right-click any custom program, and click "Modify" to open its source in MetaEditor.

5

Direct Executable Launch

Launch metaeditor64.exe (for MT5) or metaeditor.exe (for MT4) directly from the terminal installation folder or command line.

Version comparison

MetaEditor 4 vs MetaEditor 5

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.

FeatureMetaEditor 4 (MT4)MetaEditor 5 (MT5)
Target platformMT4; MQL4 source and EX4 executableMT5; MQL5 source and EX5 executable
Language modelProcedural and object-oriented MQL4Procedural and object-oriented MQL5; different trading API
Debugging and profilingBuilt-in debugger and code profilerDebugger and profiler; real-data and historical-data debugging modes
Source storageIntegrated MQL5 Storage is documented for MT4MQL5 Storage and project tools; check the installed build
Code assistanceSyntax highlighting, completion, definitions and MQL helpSyntax highlighting, completion, definitions and MQL help
Output locationBeside the main MQ4 source or projectBeside the main MQ5 source or project

IDE architecture

Key Components of the MetaEditor Workspace

MetaEditor is structured into dedicated modular panels for project navigation, code authoring, compilation diagnostics, and performance analysis.

Navigator Window

Tree structure organising MQL source directories: Experts (EAs), Indicators, Scripts, Include headers, Libraries, and Projects.

Code Editor & IntelliSense

Syntax highlighted editor featuring bracket matching, code folding, auto-formatting, line numbering, and contextual function parameter hints.

Built-in MQL Reference (F1)

Offline documentation accessible by placing the cursor on any MQL keyword or function and pressing F1, providing syntax, signatures, and code examples.

Toolbox & Errors Panel

Displays compilation messages, error codes, line numbers, search results, and MQL5 Storage repository sync status.

Debugger & Call Stack

Set breakpoints in source code, step through execution line by line, inspect local variables, and monitor call stack frames in real time.

Performance Profiler

Measures execution speed and function call frequencies across historical price data, pinpointing algorithmic bottlenecks.

Step-by-step guide

MetaEditor 5 Tutorial: From New Project to Execution

Follow this five-step walkthrough to create, code, compile, and execute your first automated program in MetaTrader 5.

1

Open MetaEditor and Launch MQL Wizard

Press F4 in MetaTrader to launch MetaEditor. Click "New" (or Ctrl+N) to open the MQL Wizard, which generates boilerplate structure.

2

Select Expert Advisor Template

For this EA workflow, select an Expert Advisor template. Indicators use OnCalculate and scripts use OnStart; they do not follow the OnTick workflow below.

3

Define Inputs and Event Handlers

Specify input parameters (such as lot size or moving average period) and select event handlers (OnInit, OnTick, OnTimer, OnDeinit).

4

Write Trading Logic and Compile (F7)

Add your trading calculations inside OnTick(). Press F7 to compile. Inspect the Errors tab to verify 0 errors and 0 warnings.

5

Execute on MetaTrader Chart

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.

Compiler Diagnostics and Runtime Errors

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

Draft Clean MQL Code Before Opening MetaEditor

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

  1. 1. Describe trading rules and indicators in plain English in Pineify.
  2. 2. Review the generated single-file .mq4 or .mq5 artifact and syntax diagnostics.
  3. 3. Copy the clean code into MetaEditor and press F7 to compile.
  4. 4. Backtest the compiled EA in the MetaTrader Strategy Tester.
Static checks do not guarantee market profitability. Always test thoroughly on demo accounts before live trading.

Official Sources & Documentation

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.

Frequently Asked Questions