Learn more about the retail trading conditions, platforms, and products available for trading that FXON offers as a currency broker.
You can't start without it.
Trading Platforms Trading Platforms Trading Platforms
Features and functionality comparison of MetaTrader 4/5, and correspondence table of each function by OS
Two account types to choose
Trading Account Types Trading Account Types Trading Account Types
Introducing FXON's Standard and Elite accounts.
close close
Support information for customers, including how to open an account, how to use the trading tools, and a collection of QAs from the help desk.
Recommended for beginner!
Account Opening Account Opening Account Opening
Detailed explanation of everything from how to open a real account to the deposit process.
MetaTrader4/5 User Guide MetaTrader4/5 User Guide MetaTrader4/5 User Guide
The most detailed explanation of how to install and operate MetaTrader anywhere.
FAQ FAQ FAQ
Do you have a question? All the answers are here.
Coming Soon
Glossary of terms related to trading and investing in general, including FX, virtual currencies and CFDs.
News News News
Company and License Company and License Company and License
Sitemap Sitemap Sitemap
Contact Us Contact Us Contact Us
General, personal information and privacy inquiries.
close close
close close
Learn more about the retail trading conditions, platforms, and products available for trading that FXON offers as a currency broker.
You can't start without it.
Features and functionality comparison of MetaTrader 4/5, and correspondence table of each function by OS
Two account types to choose
Introducing FXON's Standard and Elite accounts.
Support information for customers, including how to open an account, how to use the trading tools, and a collection of QAs from the help desk.
Recommended for beginner!
Detailed explanation of everything from how to open a real account to the deposit process.
The most detailed explanation of how to install and operate MetaTrader anywhere.
Do you have a question? All the answers are here.
Coming Soon
Glossary of terms related to trading and investing in general, including FX, virtual currencies and CFDs.
General, personal information and privacy inquiries.
Useful information for trading and market information is posted here. You can also view trader-to-trader trading performance portfolios.
Find a trading buddy!
Share trading results among traders. Share operational results and trading methods.
This article was :
published
updated
On MetaTrader4 (MT4) / MetaTrader5 (MT5), you use a programming tool called MetaEditor and a dedicated language called MQL4 or MQL5 to create an Expert Advisor (EA).
Here we will look at how to create an Expert Advisor (EA) on MT4/MT5.
Switch between MT4/MT5 tabs to check the steps for each.
Click "Tools" in the menu and select "MetaQuotes Language Editor".
MetaEditor will be launched. Click the "New" button in the menu.
Select "Expert Advisor" and click "Next".
Enter the Expert Advisor (EA) name, author, and link to display. Configure the parameters as necessary and click "Next". All fields, except for the indicator name, can be left blank.Other parameters can be adjusted directly in the code, including adding, modifying, or removing them.
Number |
Item name |
Descriptions |
---|---|---|
1 |
Name |
Enter the name of the Expert Advisor (EA) that you create. |
2 |
Author |
Enter the author of the Expert Advisor (EA). |
3 |
Link |
Enter the link to display. |
The registered name, author, and link information will be displayed on the Expert Advisor (EA) settings window.
Set event handlers, which are the functions that are called if certain conditions are met.
Number |
Item name |
Descriptions |
---|---|---|
1 |
OnTrade |
OnTrade is a function that handles changes to orders, executions, positions, and trade history when a trade is executed. |
2 |
OnTradeTransaction |
OnTradeTransaction is called by the Expert Advisor (EA) when a TradeTranscation event occurs to process the execution result of a trade request. |
3 |
OnTimer |
OnTimer is a function that runs at a specified time interval. The interval can be defined or adjusted directly within the code afterwards. |
4 |
OnChartEvent |
OnChartEvent is a function that handles events on a chart. It is executed when an event occurs on a chart, such as creating, deleting, moving, or editing an object. |
5 |
OnBookEvent |
OnBookEvent is a function that handles the changes in the depth of market data. |
Set tester event handlers to use.
Number |
Item name |
Descriptions |
---|---|---|
1 |
OnTester |
OnTester is a function used for formulas to calculate optimization results in the Strategy Tester. |
2 |
OnTesterInit |
OnTesterInit is a function that executes the initialization of the Expert Advisor (EA) when starting optimization in the Strategy Tester. |
3 |
OnTesterPass |
OnTesterPass is a function that executes data processing during optimization by the Strategy Tester. |
4 |
OnTesterDeinit |
OnTesterDeinit is a function that executes data processing after optimization by the Strategy Tester. |
Write a program in MQL4.
"MQL4, designed for MT4, and MQL5, used for MT5, share some similarities but are not compatible. Expert Advisors (EAs) created for MT4 cannot be directly used in MT5.While MQL4 is similar to the C programming language, MQL5 is closer to C++, offering greater flexibility and variety."
After writing the program, click the "Compile" button in the toolbar.
You will get a compile error as shown below if, for example, the syntax of your code is incorrect, or some files are missing.
Missing semicolons and using full-width space are the two most common mistakes made when coding in MQL4. Please check the error message to identify and resolve the issue.
After the compilation, the Expert Advisor (EA) created will appear in the Navigator.
Close the MetaEditor and go back to MT4. Check that the Expert Advisor (EA) created is in the Navigator on MT4.
Click "Tools" in the menu and select "MetaQuotes Language Editor".
MetaEditor will be launched. Click the "New" button in the menu.
Select "Expert Advisor (template)" or "Expert Advisor (generate)" and click "Next".
If you select "Expert Advisor (template)", only the fields configured during the following steps will be filled out, such as parameters and functions. If you select "Expert Adviser (generate)", it will also contain the source code of indicators that come with MT5 by default.
"Enter the Expert Advisor (EA) name, author, and link to display. Configure the parameters as necessary and click ""Next"". All fields, except for the indicator name, can be left blank.Other parameters can be adjusted directly in the code, including adding, modifying, or removing them."
Number |
Item name |
Descriptions |
---|---|---|
1 |
Name |
Enter the name of the Expert Advisor (EA) that you create. |
2 |
Author |
Enter the author of the Expert Advisor (EA). |
3 |
Link |
Enter the link of the Expert Advisor (EA) to display. |
The registered name, author, and link information will be displayed on the Expert Advisor (EA) settings window.
Set event handlers, which are the functions that are called if certain conditions are met.
Number |
Item name |
Descriptions |
---|---|---|
1 |
OnTrade |
OnTrade is a function that handles changes to orders, executions, positions, and trade history when a trade is executed. |
2 |
OnTradeTransaction |
OnTradeTransaction is called by the Expert Advisor (EA) when a TradeTranscation event occurs to process the execution result of a trade request. |
3 |
OnTimer |
OnTimer is a function that runs at a specified time interval. The interval can be defined or adjusted directly within the code afterwards. |
4 |
OnChartEvent |
OnChartEvent is a function that handles events on a chart. It is executed when an event occurs on a chart, such as creating, deleting, moving, or editing an object. |
5 |
OnBookEvent |
OnBookEvent is a function that handles the changes in the depth of market data. |
Set tester event handlers to use.
Number |
Item name |
Descriptions |
---|---|---|
1 |
OnTester |
OnTester is a function used for formulas to calculate optimization results in the Strategy Tester. |
2 |
OnTesterlnit |
OnTesterInit is a function that executes the initialization of the Expert Advisor (EA) when starting optimization in the Strategy Tester. |
3 |
OnTesterPass |
OnTesterPass is a function that executes data processing during optimization by the Strategy Tester. |
4 |
OnTesterDeinit |
OnTesterDeinit is a function that executes data processing after optimization by the Strategy Tester. |
Write a program in MQL5.
MQL4, designed for MT4, and MQL5, used for MT5, share some similarities but are not compatible. Expert Advisors (EAs) created for MT4 cannot be directly used in MT5.While MQL4 is similar to the C programming language, MQL5 is closer to C++, offering greater flexibility and variety.
After writing the program, click the "Compile" button in the toolbar.
You will get a compile error as shown below if, for example, the syntax of your code is incorrect, or some files are missing.
Missing semicolons and using full-width space are the two most common mistakes made when coding in MQL5. Please check the error message to identify and resolve the issue.
After the compilation, the Expert Advisor (EA) created will appear in the Navigator.
Close the MetaEditor and go back to MT5. Check that the Expert Advisor (EA) created is in the Navigator.
Was this article helpful?
0 out of 0 people found this article helpful.
Thank you for your feedback.
FXON uses cookies to enhance the functionality of the website and your experience on it. This website may also use cookies from third parties (advertisers, log analyzers, etc.) for the purpose of tracking your activities. Cookie Policy