Camovia Tray™

Blog · Knowledge

How to Build a Custom Expert Advisor: A Step-by-Step Guide for MetaTrader

Camovia Tray Team · 2026-09-12

Every trader has that moment—staring at a chart, watching a setup unfold perfectly, and realizing they’ve seen this pattern a hundred times before. The entry signals are clear. The risk-reward ratio makes sense. And yet, sitting in front of the screen for hours, waiting for the exact moment to click “buy” or “sell,” feels less like trading and more like babysitting.

That’s the gap a custom Expert Advisor (EA) fills.

An EA is an automated trading program built specifically for the MetaTrader platform, designed to execute your strategy without manual intervention. It doesn’t get tired. It doesn’t second-guess itself. It simply follows the rules you give it, tick by tick. Whether you want to automate a single indicator or build a fully autonomous trading system, creating your own EA gives you control over your strategy in a way that off-the-shelf solutions never can .

What You Need Before You Start

Building a custom EA begins with the MetaTrader platform itself. You’ll need either MT4 or MT5 running on your computer—the development environment is built right into the terminal. Press F4 from within MetaTrader, and MetaEditor opens. This is where the magic happens .

MetaEditor is the integrated development environment (IDE) for MQL4 (MT4) and MQL5 (MT5), the languages used to write EAs. It includes everything you need: a code editor with syntax highlighting, a compiler, a debugger for step-by-step troubleshooting, and even a profiler to identify slow functions in your code . It’s not just a text editor with a compile button—it’s a professional-grade toolkit that connects seamlessly to the trading platform.

The MQL4/MQL5 Wizard: Your Starting Point

If you’ve never written a line of MQL code, the Wizard is your best friend. It generates program templates and, in some cases, fully functional trading robots based on the standard library included with MetaTrader .

When you launch MetaEditor and create a new file, the Wizard walks you through the setup:

  1. Name and author – Give your EA a name and credit yourself as the developer.
  2. Input parameters – Define variables that users can adjust without touching the code (like lot sizes, moving average periods, or stop-loss distances).
  3. Event handlers – Choose which events your EA will respond to: the OnInit() function runs when the EA loads, OnTick() activates with every new price tick, and OnDeinit() handles cleanup when the EA is removed .

For more advanced users, the Wizard can generate a complete EA by selecting trading signals, money management rules, and trailing stop algorithms from a library of pre-built modules . You can mix and match signals—MACD crossovers, RSI overbought/oversold conditions, moving average breaks—without writing the underlying logic from scratch. The code is generated automatically, and you can fine-tune it afterward.

Understanding the Core Components of Any EA

Every Expert Advisor, no matter how complex, relies on the same fundamental building blocks :

  • Initialization (OnInit()) – Sets up indicators, checks market conditions, and prepares the EA for trading when it’s attached to a chart.
  • Main Loop (OnTick()) – The heart of the EA. Every time a new price tick arrives, this function runs your trading logic: check for entry signals, manage open positions, adjust stops, and decide when to exit.
  • Deinitialization (OnDeinit()) – Releases resources, removes indicators from the chart, and performs any cleanup when the EA is detached.

Beyond these, the real work happens in the trading functions: OrderSend() to open positions, OrderClose() to exit them, and OrderModify() to adjust stops and take-profit levels. Risk management logic—position sizing, stop-loss calculation, and drawdown controls—is woven into the decision flow.

Building Your First EA: A Simple MACD Crossover

Let’s walk through a practical example that illustrates the process.

Suppose your strategy is simple: enter a long trade when the MACD main line crosses above the signal line, and exit when it crosses back below. Here’s the workflow:

  1. Define the strategy clearly – Know your entry, exit, stop-loss, and take-profit rules before you write a single line of code.
  2. Launch MetaEditor – Press F4 from MetaTrader, then use the Wizard to create a new EA template.
  3. Add the MACD indicator – In the code, you’ll create an indicator handle using iMACD() and store it for use in OnTick().
  4. Write the logic – In OnTick(), copy the MACD values into arrays, check for crossovers, and use OrderSend() to execute trades when conditions are met.
  5. Compile and test – Press F7 to compile. If there are no errors, an executable .ex5 (or .ex4 for MT4) file is created and placed in the Experts folder .

The debugging tools in MetaEditor are invaluable here. Instead of filling your code with print statements and guessing what went wrong, you can step through your EA line by line, watching variable values change in real-time . This systematic approach turns debugging from a chaotic guessing game into a structured process.

The Real-World Challenge: Testing and Running Your EA

Getting your EA to compile is one thing. Getting it to perform the way you expect in a live environment is another.

Before you let your EA trade with real money, you’ll run it through the Strategy Tester in MetaTrader. This lets you backtest your strategy against historical data, optimize parameters, and see how it would have performed in different market conditions . But even after rigorous testing, there’s a practical gap that few developers talk about: the EA only runs when MetaTrader is open and actively connected to the market.

That’s where the daily workflow of an EA developer gets interesting.

How Camovia Tray Changes the EA Experience

When you’re building and testing a custom EA, your computer becomes a trading hub. MetaTrader is running. The EA is attached to charts. You’re watching for signals, checking open positions, and monitoring whether the code is behaving as expected. But you can’t always keep the terminal window visible—you have other work to do, other screens to manage, and moments when you need to step away.

This is where Camovia Tray becomes a practical addition to the EA developer’s toolkit.

Camovia Tray turns your MT5 or MT4 instance into a tray tool, letting you check live quotes and manage positions directly from the system tray without bringing the terminal window back to the foreground [Camovia Tray product knowledge]. For someone writing and testing an EA, this means you can:

  • Hover the tray icon to see live prices – Instead of switching windows to check whether your EA’s entry conditions are being met, a quick glance at the tray gives you the data you need [Camovia Tray product knowledge].
  • View open positions at a glance – The floating order panel shows you what your EA is doing: which positions are open, what the current profit or loss is, and whether the EA is managing them correctly [Camovia Tray product knowledge].
  • Close positions with a click – If you need to intervene—because the EA is misbehaving, the market has moved against you, or you simply want to take profits manually—you can close positions directly from the tray without opening the terminal [Camovia Tray product knowledge].
  • Hide the terminal completely – While you’re focused on writing code, refining logic, or testing in the Strategy Tester, you can keep the MT4/MT5 window off your taskbar and out of your Alt+Tab view. It’s still running, your EA is still trading, but it’s not cluttering your workspace [Camovia Tray product knowledge].

For developers who spend hours in MetaEditor debugging and tweaking their EAs, this small efficiency adds up. You don’t have to juggle windows constantly. You can leave the terminal running in the background, check in via the tray when you need to, and stay focused on what matters—the code and the strategy.

And for those who value discretion, the tray icon can be disguised as a common system icon, and the tray functions can be locked with a privacy setting when you step away from your desk [Camovia Tray product knowledge]. The data—prices, positions, and balances—remains entirely local, never leaving your computer.

From Code to Confidence

Building a custom Expert Advisor is equal parts coding, strategy design, and testing. The tools are all there: MetaEditor for development, the Wizard for getting started quickly, and the Strategy Tester for validation. But the day-to-day reality of running an EA involves more than just the code—it’s about staying connected to what your EA is doing without letting it take over your screen.

That’s the practical gap Camovia Tray fills for traders who want to keep their focus on development while staying in control of their live positions. Whether you’re a seasoned MQL developer or just getting started with your first automated strategy, reducing the friction of managing the terminal lets you spend more time improving your EA and less time wrestling with windows.

Turn MT5 / MT4 into a Tray Tool

Check quotes, manage positions, and hide in one click.

Download Camovia Tray

Frequently Asked Questions

Which languages are supported?

Chinese and English, switchable on both the website and the client.

How do I download it?

Install from the Microsoft Store - the download page on this site has the link.

How do I report issues or contact you?

Send an email to [email protected].

Where are the privacy policy and user agreement?

The "Privacy" and "EULA" links in the footer of this site, with GDPR/CCPA information included.

Popular Symbols Trading Hours

Open/close times, weekend hours & live market status: