Beginner's Guide to Writing an EA on MT4 using MQL4


Investment and Financial Freedom > Beginner's Guide to Writing an EA on MT4 using MQL4
30/03/2025 07:30 59


What are MQL4 and MT4?


MQL4 (MetaQuotes Language 4) is a programming language used for creating Expert Advisors (EAs), Indicators, Scripts, and Custom Functions on MetaTrader 4 (MT4), which is a popular Forex trading platform.


  • MetaTrader 4 (MT4) – A software for trading Forex and CFDs that includes chart analysis tools and supports automated trading.
  • MQL4 – A language for developing EAs to perform automated trading or create custom indicators.

How to start writing an EA on MT4


1. Install MetaTrader 4 and MetaEditor


  • Download MT4 from your broker.
  • Open MT4 and press F4 to open MetaEditor (the code editor for MQL4).



Create a new EA file


  • In MetaEditor, go to File > New
  • Select Expert Advisor (template).
  • Name the file, e.g., MyFirstEA.
  • Click Next > Finish.









Basic structure of an EA


The basic code of an EA consists of three main functions.





How to test an EA on MT4


Once the code is written, press Compile to convert it into a .ex4 file and check that there are no errors. If there are no errors, the EA is ready for use.




Then, open MT4, go to Navigator > Expert Advisors, and drag the EA onto the desired chart window. Now, the newly created EA will run on your chart.


Make sure to check the smiley face icon at the top right of the chart. If it is not smiling, it means EA trading is not enabled for your account. You need to enable it as follows:




Go to the Tools menu > Options, then check the One Click Trading box.




Next, go to the Expert Advisors tab, check "Allow automated trading," and enable other relevant options as shown. Then, drag the EA onto the chart again to ensure the smiley face appears in the top right corner. Now, everything is set up correctly.





Please rate your satisfaction with this article

Star 1 Star 2 Star 3 Star 4 Star 5

Post a Comment
Your email address will not be displayed to others. Required fields are marked *

CAPTCHA