Home | MQL4 Tutorial For Dummies | Blogs | EA Builder Blogs
Memberships Login | MQL4 Course | Community | Contact Us

MQL4 Tutorial for Dummies

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!

1. Write Down Your Trade Criteria

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.

2. Create a Default EA Template from MetaEditor.exe

On Metatrade 4 terminal, open MetaQuates Language Editor.

Click on the NEW button

Choose Expert Advisor (template) and click Next button.

3. Transform Your Criteria into Codes

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.

Download EA script here.

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.

4. Let the EA run on Metrader 4

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.

Insert two moving averages (5 exponential moving average in blue color and 13 simple moving average in orange color) in 5 minutes chats as below


5. Experience the EA Robot

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.

More Free Tutorial for MQL4 Dummies

  • How to write MQL4 custom indicator tutorial step by step
      How to write MQL4 Custom Indicator Step by Step What you’ll learn in this video How to create default indicator template How to use the onCalculate Event Prerequisites You must know the basic core knowledge before continue this tutorial You must [Read more]
  • Best Expert Advisor Builders
    Best Expert Advisor Builders   What is the available best EA builder ? Which EA Builder covers the most features in checking condition? Which EA is the most reliable and easy to be used without the knowledge of MQL4 programming ? Before I start on [Read more]
  • How to Compare Multiple Conditions using AND OR in Forex Trading Strategy
    How to Compare Multiple Conditions using AND OR in Forex Trading Strategy In previous post, you have learned how to use the relational operators to build a single criteria check. more than, lesser than, more or equal than, lesser or equal than, equal not [Read more]
  • How to Use More Than, Lesser Than, Equal, Not Equal in Forex Trading Strategy
    How to use more than , lesser than, equal or not equal in Forex Trading Strategy  As a part of how to design your forex trading strategy,  you need to know what is the condition that you could check for ? In general, you know you could compare the price, [Read more]
  • How to Design Your Forex Trading Strategy
    How to Build EA Robot Strategy | How to Design Your Forex Trading Strategy This post is to show you how to build a good forex trading strategy for your trade or for your EA robot. A good strategy covers different aspects from trade entry, trade [Read more]

2 Comments Posted

Leave a Reply

Your email address will not be published.