Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
If you’ve ever stared at an MT4 indicator thinking, “Why can’t this just place the trade for me?”, you’re in the right place. Building an EA that “listens” to an indicator is one of the most practical ways to automate a strategy—because the indicator already does the heavy lifting of reading price action, and the EA can handle the boring stuff: entries, exits, and risk rules.
This article walks you through the full process—without drowning you in jargon—so you can design an automation plan that’s testable, safer, and easier to maintain.
At its core, it means this:
In MT4, the EA is the “doer,” not the indicator. Indicators are excellent for analysis and visualization, but EAs are designed for automated trading actions.
Here’s the simplest way to remember it:
MT4 automation is generally EA-driven because EAs are built to respond to market updates and perform trading operations.
Most traders want one (or more) of these:
Before you automate anything, you need one big idea:
EAs are event-driven.
The most common event is a new tick, handled by OnTick() in an EA. The platform also runs initialization logic in OnInit() when you attach the EA.
OnInit() runs once when the EA is attached or reloaded.OnTick() runs whenever there’s a new quote tick for the chart symbol.Because your EA “wakes up” on ticks, your strategy logic should answer:
For many strategies, a safer approach is:
Trade based on closed candles (more on that soon).
Not all indicators are automation-friendly.
A repainting indicator can change historical signals after the fact. It may look amazing on the chart but fail horribly live.
Simple ways to reduce pain:
Common patterns include:
The easiest to automate reliably is usually a numeric buffer value you can read consistently.
This is where most people trip.
In MT4, one standard way to read a custom indicator from an EA is using iCustom(), which calculates/returns indicator values.
Think of it like:
iCustom() returns a double value for the buffer/shift you request.
A classic safety rule:
shift = 1 for entries (last closed candle)shift = 0 for signals that might change mid-candleWhy? Because the current candle is still forming, and the indicator can “wiggle.”
A signal is not a system until you define:
Examples:
Good rule:
One entry per signal, not multiple entries on every tick.
You can exit with:
Many robust EAs mix both:
If your EA is “smart” but your risk is reckless, it’s still a disaster.
Popular options:
Consider adding:
An EA typically uses trading functions to open/modify/close orders. MetaQuotes provides examples and standard structures for EAs that form trade requests and manage orders.
Real brokers have constraints like:
A practical EA includes:
Filters often matter more than the indicator itself.
Examples:
Add rules like:
These filters cut a lot of garbage trades.
MT4 includes a Strategy Tester designed for testing and optimizing EAs before using them live.
It runs the EA through historical data and simulates OnInit() and OnTick() events.
Testing quality depends on the modeling method and the historical data you have. MetaQuotes has also discussed how modeling choices affect accuracy.
A good backtest routine:
Avoid curve-fitting by:
Even a small mistake can ruin an EA.
Simple monitoring tools:
Before going live:
Typically, trade execution is handled by an EA, not a chart indicator. The automation layer is usually built as an EA that reads indicator values.
Use closed-candle confirmation (for example, read signal at shift 1) and add filters like spread and session restrictions.
A common approach is using iCustom() to fetch values from indicator buffers.
Because it’s probably checking the signal every tick and lacks a “one trade per signal” rule—often solved with a “new bar” check and state tracking.
It’s useful, but accuracy depends on data quality and modeling assumptions. Treat backtests as a filter, not a guarantee.
Automating a repainting signal without realizing it—then trusting backtest results that won’t repeat live.
Building an EA around an indicator is a smart and practical path—especially when you keep the rules simple, confirm on closed candles, and protect your account with strong risk controls.
If you want the cleanest result, treat the indicator as a signal source, and make the EA your risk manager + execution engine.