Platforms Metatrader 4 MT4 Automation

MT4 Automation (Expert Advisors and Automated Trading)

One of the most exciting features of MetaTrader 4 is the ability to automate your trading. Instead of sitting at your computer watching charts all day, you can use a program called an Expert Advisor (EA) to place trades for you based on rules you define. In this guide, we explain how automation works on MT4, how to get started, and what pitfalls to avoid.

Risk warning: This content is for educational purposes only and not financial advice. Forex trading involves risk, and you can lose money.

Forex MT4 automation

MT4 Automation (Expert Advisors and Automated Trading)

  • What is an Expert Advisor
  • How to install an Expert Advisor
  • How to attach an EA to a chart
An Expert Advisor is only as smart as the rules you give it, so give it smart rules.

What is an Expert Advisor

An Expert Advisor is a small program that runs inside MT4 and makes trading decisions automatically. You attach it to a chart, and it monitors price movements in real time. When conditions match the rules programmed into it, the EA places buy or sell orders, sets stop-losses and take-profits, and even closes trades, all without your input.

Think of an EA as a recipe that the computer follows. For example, an EA might be programmed to "buy when the 50-period moving average crosses above the 200-period moving average, and place a stop-loss 30 pips below the entry." Every time that condition occurs, the EA executes the trade.

EAs are written in MQL4, the programming language built specifically for MetaTrader 4. You do not need to be a programmer to use EAs, though. There are thousands of pre-built EAs available that you can download and use right away.

How to install an Expert Advisor

Installing an EA follows a similar process to custom indicators.

  • Download the EA file. It will be an .mq4 or .ex4 file.
  • Open MT4 and go to File, then Open Data Folder.
  • Navigate to MQL4, then Experts.
  • Copy the EA file into the Experts folder.
  • Restart MT4 or right-click on Expert Advisors in the Navigator and select Refresh.
  • Your EA should now appear in the Navigator under Expert Advisors.

How to attach an EA to a chart

Once installed, you need to attach the EA to the chart of the currency pair you want it to trade.

  • Open a chart for the desired currency pair and timeframe.
  • From the Navigator panel, drag the EA onto the chart (or double-click it).
  • A settings window will appear. On the Common tab, make sure "Allow live trading" is checked.
  • On the Inputs tab, configure the EA's settings (lot size, stop-loss distance, strategy parameters, etc.).
  • Click OK.

You also need to enable automated trading globally. Look at the top of your MT4 toolbar for the AutoTrading button. Make sure it is turned on (the button should appear green, not red).

When the EA is running, you will see a smiley face icon in the top-right corner of the chart. If you see a frowning face or an X, the EA is not active and you need to check your settings.

Types of Expert Advisors

EAs come in many varieties, designed for different trading styles.

  • Trend-following EAs look for strong price movements in one direction and place trades to ride the trend.
  • Scalping EAs make many small trades throughout the day, trying to capture tiny profits on each one. These are popular for scalping strategies and need fast execution and low spreads to work well.
  • Grid EAs place multiple orders at fixed price intervals, creating a grid pattern. They can be profitable in ranging markets but risky in trending ones.
  • Martingale EAs double the position size after each losing trade, hoping to recover losses with one winning trade. These are very risky and can blow up your account quickly.
  • News-trading EAs try to trade around major economic events. They place orders just before news releases to catch the big price moves.

Where to find Expert Advisors

  • MQL5.com Marketplace has both free and paid EAs with user reviews and ratings.
  • MQL5.com Code Base offers free, open-source EAs that you can study and modify.
  • Trading forums like Forex Factory have sections where members share EAs.
  • Freelance developers can build custom EAs based on your specific strategy.

Important warnings about automated trading

No EA guarantees profits. If someone tells you their EA makes guaranteed money, they are either lying or confused. All trading strategies have losing periods. Automation does not eliminate risk.

Backtest before you go live. Always test your EA on historical data using MT4's Strategy Tester before risking real money. Learn more about backtesting to understand how this works. Keep in mind that past results do not guarantee future results.

Demo test after backtesting. Even if an EA looks great in backtesting, run it on a demo account for several weeks or months. Real market conditions can differ from backtesting results due to slippage, spread changes, and execution delays.

Watch out for over-optimization. Some EAs are tuned so perfectly to past data that they fail in live trading. This is called curve-fitting. A good EA should perform reasonably well across different time periods and conditions, not just on one specific slice of history.

Keep your EA running. For an EA to work, MT4 must be open and running. If you close the platform, shut down your computer, or lose your internet connection, the EA stops. This is why many traders use a VPS (Virtual Private Server) to keep their EAs running 24/7.

Start with small positions. When you first go live with an EA, use the smallest possible lot sizes. This limits your risk while you confirm that the EA works correctly in real market conditions.