How to Include Files in MQL4 Code with #include
Camovia Tray Team · 2026-09-12
You've just spent hours writing a beautifully structured Expert Advisor. Your entry logic is clean, your risk management is solid, and your exit conditions are exactly what your strategy demands. Then you look at the code—all 1,500 lines of it—and realize you need to reuse the same position sizing logic in three other EAs you're building. Copy-paste feels wrong. You know there has to be a better way.
There is. And it's called the #include directive.
What the #include Directive Actually Does
In MQL4, the #include directive tells the compiler to insert the entire contents of another file into your source code at compile time . Think of it as a copy-paste that happens automatically when you build your executable .ex4 file . The preprocessor replaces every #include line with the full content of the referenced file before compilation finishes.
The syntax is simple:
#include <file_name.mqh> // Searches in the standard Include folder
#include "file_name.mqh" // Searches in the current directory Angle brackets (<>) tell the compiler to look in the standard MQL4 include directory—typically terminal_installation_directory\MQL4\Include . Quotation marks ("") tell it to look in the same directory as your main source file .
Why You Should Use Include Files
The MQL4 documentation puts it plainly: include files are "source text of the most frequently used blocks of custom programs" . They're preferable to libraries because they impose less runtime overhead—no extra burden from calling external functions .
For developers building multiple EAs, indicators, or scripts, include files transform scattered code into maintainable, reusable components. Instead of debugging the same risk calculation in five different EAs, you fix it once in your include file and every EA that references it gets the update automatically.
A well-structured Expert Advisor might include standard files like these at the top:
#include <stdlib.mqh>
#include <stderror.mqh>
#include <WinUser32.mqh> These provide essential constants, error handling definitions, and Windows API mappings . From there, you'd include your own custom modules—variable definitions, trading functions, event tracking, and order management logic .
The Two Search Paths You Need to Know
The distinction between angle brackets and quotation marks matters more than you might think.
With angle brackets (#include <filename.mqh>), the compiler only checks the standard MQL4 Include folder. It does not look in your current project directory . This is ideal for referencing system-wide files that ship with MetaTrader or libraries you want available to all your projects.
With quotation marks (#include "filename.mqh"), the compiler searches the current directory—the folder containing your main source file . It does not look in the standard Include folder . This is perfect for project-specific helper files that shouldn't pollute the global include directory.
This subtle behavior means you can organize your code flexibly: keep shared utilities in the global Include folder for easy access across projects, and keep strategy-specific helpers local to each EA.
Common Pitfalls and Practical Tips
Multiple inclusions: If you include the same file twice—say, through nested includes—the compiler will duplicate its contents. Unlike C/C++, MQL4 doesn't have a standard #pragma once or include guard mechanism . This can lead to duplicate definition errors. The workaround? Be mindful of your include structure and avoid circular dependencies.
Variable scope: Global variables declared in your EA are accessible to functions defined in included .mqh files . The order matters—if your include file references an input variable, you should include that file after declaring your input parameters .
Compilation behavior: You don't compile .mqh files directly. You compile the main .mq4 file; the compiler pulls in all included .mqh files at build time and generates a single .ex4 executable . The .mqh files themselves don't need to be present on other computers for the compiled .ex4 to run—everything is already baked in .
No macro-based includes: A common question is whether you can use macros to construct include paths. The answer is no—MQL4's preprocessor doesn't support this . The path must be a literal string.
A Scenario That Hits Close to Home
Imagine you're an active trader with multiple EAs running simultaneously on MT4. You've developed a family of strategies—each with different entry rules, but all sharing the same position management and risk allocation logic. Every time you update the risk module, you find yourself manually updating code across five different EAs. It's tedious, error-prone, and takes time away from actual trading.
After restructuring with include files, your workflow changes completely. You extract the shared logic into RiskManager.mqh and PositionSizer.mqh. Each EA now starts with:
#include "RiskManager.mqh"
#include "PositionSizer.mqh" One change to the risk module updates every EA that uses it. You spend less time maintaining code and more time analyzing markets.
And when you're deep in that analysis, you don't want to be distracted by terminal windows cluttering your screen. You need quick access to your open positions and live quotes without the overhead of keeping MetaTrader's full interface visible. While you're coding and testing, Camovia Tray turns your MT4 into a system tray tool—letting you check your running EAs' performance, view open positions, and even close trades with a few clicks, all without restoring the main MT4 window [Product Knowledge]. When you're iterating on your EA code and need to monitor live results, it keeps your workflow focused and your screen uncluttered.
The #include directive is one of those features that seems trivial until you need it. Then it becomes indispensable. Whether you're building a single EA or managing a portfolio of strategies, organizing your code with include files saves time, reduces errors, and makes your MQL4 development professional and maintainable.
Turn MT5 / MT4 into a Tray Tool
Check quotes, manage positions, and hide in one click.
Download Camovia TrayFrequently Asked Questions
What is Camovia Tray?
A Windows desktop app that turns MT5/MT4 into a tray tool: hover the system tray to check the latest quotes and manage open positions (click an order to close it), hide the MT5/MT4 main window in one click, and keep quote and position data entirely on your computer.
Do I need MT5/MT4 installed? Does the terminal need to stay open?
Yes. Camovia Tray reads quote and position data from your locally running MT5/MT4 terminal, so the terminal must be installed, running, and logged in. MT5 connects directly with no EA; MT4 needs the bundled bridge EA attached once (one-click copy in Settings, then double-click in the Navigator - see the docs).
Are my quotes and positions uploaded anywhere?
No. Quote and position data is read 100% from your local MT5/MT4 terminal and never leaves your computer. See the privacy policy for details.
Which systems and terminals are supported?
Windows 10 / 11, with MetaTrader 5 or MetaTrader 4 (installed and logged in; MT4 needs the bridge EA attached once).
Popular Symbols Trading Hours
Open/close times, weekend hours & live market status:
Related Articles
The MQL4 to MQL5 ChatGPT Conversion Trap: What Every Trader Gets Wrong
Discover the MQL4 to MQL5 ChatGPT conversion trap and why AI code migration often fails. Learn what to fix and how Camovia Tray streamlines your MT5 workflow.
The MT5 Trade Shortcut List: What You’re Missing (And How to Fix It)
Stop memorizing hotkeys you can't use. Camovia Tray turns MT5 into a system tray tool—check live quotes & manage positions without reopening the terminal.
How Close Are You to the Stop-Out Line? A Question Most Traders Can't Answer in Real Time
Learn how close you are to the stop-out line in real time. Camovia Tray lets you monitor positions and margin risk from your system tray without opening MT5/MT4.
MT5 and Kraken: Bridging Traditional Charting with Crypto Markets
Camovia Tray lets you manage MT5 and Kraken-integrated crypto data from your system tray - check quotes, view positions, and hide MT5 windows while keeping everything local.
Infinitytron_EURUSD_M5 EA Review Draft: Performance, Risk, and the Quiet Utility of Managing It
Turn your MT4 into a tray tool with Camovia Tray while running Infinitytron_EURUSD_M5. Check quotes, view open positions, and hide the terminal—all from the system tray.