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.
MT4/MT5 Tray Assistant
Silent tracking, one-click close - check quotes and manage positions right from the tray.
Download Camovia TrayFrequently Asked Questions
What is Camovia Tray?
A tray assistant for MT4/MT5 - silent tracking, one-click close: 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).
Online Tools
Popular Symbols Trading Hours
Open/close times, weekend hours & live market status:
Related Articles
CME Trading Hours Thanksgiving: What Futures Traders Need to Know Before the Holiday
CME trading hours Thanksgiving week are shortened—check the modified schedule for CME futures trading hours Sunday, holiday closes, and how Camovia Tray helps you monitor MT4/MT5 quotes and positions from the system tray.
MetaTrader Expert Advisors and Timed Orders: The Hidden Problem Nobody Talks About
Discover how timed-order Expert Advisors in MetaTrader can fail due to clock drift and timezone confusion. Camovia Tray lets you monitor live quotes and manage positions from your system tray—keeping visibility and control over automated trades without opening MT4 or MT5.
The Hidden Power of Input Parameters in MetaTrader Programs
How input parameters in MetaTrader programs work—extern/input, optimization ranges, defaults—so EAs adapt to any market without recoding.
Why a 90% Win Rate Gold Strategy Still Blows Up
Small wins plus rare large losses is the classic gold blow-up shape. See the streak math behind a 90% win rate, and Camovia Tray keeps drawdown visible.
CBOT Opening Times: What Traders Get Wrong About the Chicago Board of Trade Schedule
Stay on top of CBOT opening times and session changes without watching your terminal all day—Camovia Tray turns MT5/MT4 into a tray tool so you can check quotes and manage positions from the system tray, with all data staying on your computer.
More Articles
How to Use a Drawdown Calculator to Protect Your Trading Capital (Without Leaving Your Charts)
Discover how Camovia Tray helps you manage drawdown risk by providing instant access to open positions and floating P&L directly from your system tray—no need to leave MT5/MT4.
MetaTrader 5 vs XT: Which Platform Should You Choose and How to Monitor Both Effortlessly?
Transform your MT5 into a tray tool with Camovia Tray. Check live quotes and manage positions from the system tray without opening the terminal.
How to Backtest a Strategy in MT5 Step by Step
Learn how to backtest a strategy in MT5 step by step. Discover how Camovia Tray helps you monitor live positions and manage trades right from your system tray.
The Ichimoku EA Challenge: Why Watching the Cloud Matters More Than You Think
Discover how Camovia Tray solves the Ichimoku EA monitoring challenge—view live quotes and manage open trades from your system tray while keeping MT5/MT4 hidden.
How to Find High Volatility Stocks Before They Break Out
Discover how to find high volatility stocks before they break out using scanners, volume, and catalysts. Camovia Tray helps MT5/MT4 traders manage positions instantly from the system tray.