This section, we will teach you how to create an expert advisor for MT4 Metatrader 4. This section is typically a mt4 programming for dummies who has not create any EA or Robot before. This is a good start for a dummy to create their first robot. Be excited!
For all kind of programming, you must know the flows of your programs. For MQL4 programming, you need to know the criteria of your trades, whether is criteria for entering or modifying or closing a trade. In other words, you need to plan out your trade strategies. Trade strategies are the soul a program. In the other word, the success of an EA is determined by trade strategies.
For example: In 5 minutes chart, I create a buy trade on previous closed bar high in when previous 5 EMA (Exponential Moving Average) is higher than previous 13 SMA (Simple Moving Average). On the othe hand, I’ll create sell trade when 5EMA is smaller than 13 SMA. For the each of the trade, take profit will be 10 pip and cut lost will be 20 pip.
To write an EA, you need to know the syntax of MQL4. To understand the syntax, you can learn yourself through MQL4 book website through. However, if you need further guidance, please go through the consultation that we offer to you.
In this tutorial, we will provide you full solution of EA from the example given in 1.1. The code is written as below. This is an perfect exercise for beginner whom never build a EA before. Download and copy the content to the EA script.
Upon copying the EA, remember to save the file by click on File menu > Save or CLTR+S to save the modification. After that click on the Compile button on the toolbar. For your knowledge, “compilation” is an action to convert human understanding code to binary code that is understood by MT4.
Upon compilation successful, you will see the message in Errors tab of Toolbox. The message “0 error(s), 0 warnings(s), compile time: (compile time)” will be shown. This shows that the EA has been compiled successfully and we are ready to use the EA in MT4.
Now, this is the time we run the EA that we have wrote run in Metatrader 4 terminal. REMINDER: if you are using real Forex account, please change to demo account to test on the EA. The EA will perform buy and sell trade. We will want you to ruin your real account balance.
Now shift the focus back to Metatrader 4, look at the left panel. Under Expert Advisor, there is look for myEA.
Make sure your Metatrader has an active chart. For example, I am opening USDJPY chart loading 15minute timeframe.
Double click on the myEA icon from the navigation toolbar or drag the myEA icon and drop into EURUSD chart. Expert – myEA dialog will be shown as below. The tabs contain EA properiatory details , trading options and input parameter tabs.
At the “Common” tab, checked on “Allow live trading”. Then click OK button.
Following that, ensure “AutoTrading” button is enabled.
If the button is in red stop icon, click on the button to enable AutoTrading.
Now with this been turned on, basically you allow EA to perform trading on your account. You are responsible on your account and know what is the EA is doing.
Another indicator to prove EA has been successfully run in Metatrader 4 is you could see a smiley face 🙂 on top right of the symbol graph.
Let the EA run for couple of 5 minutes, you will see the multiple trades are been added into terminal if the conditions are met. The chart below shows when a sell condition is met where a sell trade is made with Take profit pip and cut lost pip.
Now you have a clear picture how to build a EA from the scratch and how to run EA. Hope this tutorial will able to help you grab a better idea on EA works in Metatrader 4.
This tutorial will guide you step by step in building your first Expert advisor script using MetaQuates Language Editor. Through different sections, you will understand how a MQL4 script is build from scratch, how to build it, and how to run it from MT4. Let’s go through it together.