
Learn how to create an MT5 Expert Advisor, add MQL5 trading code, compile your Forex trading bot, and prepare it for backtesting.
Automated trading allows traders to execute a trading strategy using software instead of manually placing every trade. In Forex, these programs are commonly called trading bots or Expert Advisors (EAs).
In the previous chapter, From Trading Strategy to MQL5 Code: How to Create a Forex Trading Bot Using ChatGPT and MQL5, we learned how to convert a Forex trading strategy into clear rules and use ChatGPT to generate MQL5 code for an Expert Advisor (EA).
This tutorial is divided into two separate parts.
In Part 1, we will create or connect a trading account, open MetaEditor, create an Expert Advisor, add our trading code, compile it, and save the EA.
In Part 2, we will learn how to backtest the Expert Advisor using historical market data, configure the Strategy Tester, and understand its performance metrics.
You do not need to be an experienced programmer to follow this tutorial. However, understanding what your trading code does is important before testing it or considering live trading.
Before creating an Expert Advisor, we need to open MetaTrader 5 and connect it to a trading account.
For this tutorial, we will use a demo account. A demo account allows us to practise using the platform without risking real money.
Open MetaTrader 5 on your computer.
If you have not installed MT5, download the platform from your broker's official website or the MetaQuotes website.
Once the platform opens, locate the account section.

You can either connect an existing trading account or create a new demo account.
For learning and testing, select the demo account option.
A demo account provides virtual funds that can be used to practise trading and understand how the platform works.
It is useful for beginners because it allows you to explore trading features without depositing real money.
MetaTrader 5 may display available brokers and demo account servers.
Select your broker if you already have an account with one.
If you do not have a broker account, you can choose an available MetaQuotes demo server for practice, depending on the options displayed in your platform.
The available servers and account options may differ depending on your MT5 installation and broker.
Follow the account creation instructions displayed by the platform.
Enter the required details and complete the account setup.
Once the account is created, connect to it and confirm that MetaTrader 5 is displaying the account information.

We have now completed the account setup. Next, we will create our Expert Advisor using MetaEditor.
An Expert Advisor is a program that can execute trading-related instructions according to its coded rules.
In MetaTrader 5, Expert Advisors are generally written using MQL5, the platform's programming language.
For this tutorial, we will use the trading strategy code created in our previous chapter.
MetaEditor is the development environment used to create and edit MQL5 programs.
You can open it from MetaTrader 5 by selecting the MetaEditor option(IDE) or using the platform's shortcut.
MetaEditor will open in a separate window.

Inside MetaEditor, select the option to create a new project from file section.
The MQL5 Wizard will guide you through creating the Expert Advisor.
This wizard generates a basic EA template that we can use as the starting point for our trading bot.
In the MQL5 Wizard, select Expert Advisor (template).
Enter a name for your Expert Advisor. For this tutorial, we will use:
TradeTogetherIN
The wizard will generate the corresponding EA source file.
Once the wizard completes, the new Expert Advisor file will open in MetaEditor.

Open the newly created TradeTogetherIN.mq5 file.
In the previous chapter, From Trading Strategy to MQL5 Code: How to Create a Forex Trading Bot Using ChatGPT and MQL5, we created an example MQL5 code for our trading strategy using ChatGPT.
For this tutorial, we will use that code to practise creating our first Expert Advisor.
If you already have MQL5 code for your own trading strategy, you can use your own code instead.
The wizard-generated template contains default code. Remove the default template code that we are replacing.
Then:
Open the previous article and copy the MQL5 code we created.
Return to MetaEditor and open TradeTogetherIN.mq5.
Paste the copied code into the file.
If you have your own EA code, paste your own code instead.
Save the file.

We have now added our trading strategy code to the Expert Advisor.
Next, we will compile the code and check whether it contains any errors.
After adding the code, we need to compile it.
Compilation converts the MQL5 source code into an executable format that MetaTrader 5 can use.
In MetaEditor, select the Compile option. You can also use the platform's compilation shortcut.
MetaEditor will process the code and display the compilation results.

After compilation, check the results displayed in MetaEditor.
The compiler may report:
If the compiler reports errors, review the messages and the relevant code.
A successful compilation means the code passed the compiler's checks. It does not mean that the trading strategy is profitable, that every trading condition works as intended, or that the EA is ready for live trading.
If the code compiles successfully, we can proceed to save and locate our Expert Advisor.
Save the Expert Advisor in MetaEditor.
The file should be available in the appropriate MetaTrader 5 data folder under the MQL5/Experts directory.
If you created the EA using the MQL5 Wizard, MetaEditor normally saves it in the relevant Experts folder.
You can locate the platform's data folder through MetaTrader 5's File → Open Data Folder option.
We have now created and compiled our Expert Advisor.
The EA is ready for the next stage of the tutorial: testing its behaviour using historical market data.
We have now taken an important step towards building an automated Forex trading system. We started by setting up MetaTrader 5, created an Expert Advisor, added our MQL5 code, and learned how to compile it.
However, this is only the beginning. In the next part, we will learn how to backtest our Forex trading bot using the MetaTrader 5 Strategy Tester, analyse its results, and understand how it performs using historical market data.
If you are completely new to automated trading and want to learn everything from the basics, explore our Forex Automated Trading Masterclass.
This learning series is designed to guide you step by step—from understanding automated trading and converting your trading strategy into clear rules, to creating MQL5 code, building your own Expert Advisor, compiling it, backtesting it, and learning how to prepare it for automated execution.
Whether you are a beginner or an experienced trader, our goal is to help you understand the complete automation process so that you can gradually learn to turn your own trading strategies into code, test them, and develop your own automated trading systems.
The MQL5 Wizard can generate a basic Expert Advisor template, but the trading strategy still needs to be implemented in code. Beginners can use existing code as a starting point and learn how it works.
Compiling converts MQL5 source code into an executable format that MetaTrader 5 can use. It also reports errors and warnings that help identify coding problems.
No. Compilation checks the code, not the profitability of the trading strategy. The EA must be tested, and historical results do not guarantee future performance.
Expert Advisors are generally stored in the platform's MQL5/Experts directory. You can locate the data folder through File → Open Data Folder in MetaTrader 5.

Written & Reviewed by
Multi-Timeframe Technical Analysis & Market Education Desk
TradeTogether Research is a market analysis team publishing structured forex, gold, and crypto technical studies, liquidity breakdowns, and trading education. Read about our research process on the About page, review our Editorial Policy, or see our Risk Disclaimer.