My EA Builder 1.1
User Guide
COPYRIGHT 2014. MyEABuilder.com.
Table of Contents
MAIN FEATURES ... 3
PCREQUIREMENTS ... 3
INSTALLATION ... 4
METATRADER SETUP ... 4
MY EABUILDER GRAPHICAL USER INTERFACE “GUI” ... 6
A SIMPLE MOVING AVERAGE EA ... 7
GENERATING THE EA FOR METATRADER ... 13
EXPERT ADVISOR VARIABLES ... 14
Common Variables ... 16
COMPLEX TRADING CONDITIONS ... 17
Creating an MA Crossover ... 18
MULTI TIMEFRAME MULTI CURRENCY EAS ... 18
My EA Builder
My EA Builder for MetaTrader is a tool to create your own Expert Advisors. With My EA Builder you do not need to write code. You only need to drag, drop, and connect EA blocks. It is as easy as a kids puzzle.
M
AIN
F
EATURES
Visual tool
No need to write MQL code Easy to use
Creates complex expert advisors using technical indicators, custom indicators, currency quotes, and candle prices
Generates MetaTrader variables to be used in backtesting and optimization Reduces EA development time to minutes
Supports hedging and ecn brokers Generates EAs for 4 and 5 digit brokers
Supports Expert Advisors with multiple currencies and multiple timeframes. Allows importing custom indicators
Supports forex signals with custom alerts and emails Great FREE support at myeabuilder.com/forum
Based on template EA building so you can leverage on our code to learn MQL
PC
R
EQUIREMENTS
My EA Builder needs:
I
NSTALLATION
-Install java from http://java.com -Install My EA Builder
M
ETA
T
RADER
S
ETUP
After installation you need to setup the MT4 directory and data folder in My EA Builder. The set up is required if you want My EA Builder to create and compile EAs in the MetaTrader directory. If you do not set up MT4 you can save the EA using the “Save as” button in the Displaying Code window.
The Set MetaTrader option tells My EA Builder the location of mql.exe (MT4 Compiler). Typically it is located on C:\Program Files\MetaTrader 4
The MetaTrader Compiler (mql.exe) is used to create the EX4 files or compiled EAs. The EA code has an mq4 file extension, compiled EAs have an ex4 file extension.
In new MT4 versions, the MT4 Compiler was renamed from Metalang.exe to mql.exe. In some new versions mql.exe does not exist. If you cannot find the file mql.exe in your MetaTrader installation you can download it here:
http://files.metaquotes.net/metaquotes.software.corp/mt5/mql.exe for Windows 32 bits
http://files.metaquotes.net/metaquotes.software.corp/mt5/mql64.exe for Windows 64 bits (You need to save it in C:\Program Files\MetaTrader 4 as mql.exe and not as mql64.exe)
The Set MetaTrader Data Folder option, tells My EA Builder the location of the Experts directory. EAs should be saved in the Experts directory.
In older MT4 builds (Before Build 600) the Experts directory was located in:
C:\Program Files\MetaTrader 4 and EAs where saved on C:\Program Files\MetaTrader 4\Experts
In newer MT4 version the Experts directory location depends on your windows version: -For old windows versions the Experts directory is located in:
C:\Program Files\MetaTrader 4\MQL4 and EAs should be in C:\Program Files\MetaTrader 4\MQL4\Experts
-If you use Windows Vista or a newer Windows Version the Experts directory is in the MQL4 directory in the MT4 Data Folder (EAs are not located in C:\Program Files\MetaTrader 4\MQL4\Experts)
In the data folder, click on MQL4 and you will be located in the Experts directory. It may
looks like:
C:\Users\YourWindowsUser\AppData\Roaming\MetaQuotes\Terminal\YourTerminalID\M QL4
To setup the Data Folder, Click on Set MetaTrader Data Folder and look for the Experts directory.
If you have issues generating EAs make sure to click on the Test Now! Button. It
will tell you the setup errors if any.
M
Y
EA
B
UILDER
G
RAPHICAL
U
SER
I
NTERFACE
“GUI”
At any point, If you want to delete components or EA blocks, drag them and drop them on top
of the garbage can. You can also drag them and drop them on the left panel.
The left panel is organized by block types to give you easy access to
components. You can also use the search option to look for a component or
block.
A toolbar with the most important options allows you to Save, Verify and
generate the EA Code.
A
SIMPLE
M
OVING
A
VERAGE
EA
The Moving Average EA is the simplest EA. It follows these rules:
-Buy when the fast (or short) period moving average is above the slow (or long) period moving average.
-Sell if the opposite condition is true.
To start creating the EA, click on EA set up, then drag the “Max Number of Open
Positions” block and drop it in the center panel:
The Max Number of Open Positions allows you to control the number of opened positions per pair. If you set it to 1, the EA will only open one position per pair. Click on the block and set it to 1.
Drag and drop the “Every Bar Do This” block into the center panel. Expert Advisors are executed every time there is a new price update or quote (or every tick). If you want your EA to be executed every bar, you need to add the EA logic inside the “Every Bar Do This” block. Blocks that are not inside the “Every Bar Do This” block are executed every tick (or price update)
The red X image is the suggestion feature; it shows a list of possible blocks that can be included inside the “Every Bar Do This” block.
You can add blocks from the left panel or using the suggestion feature. Click on the red X and
select the “ifelse” block from the Trading Logic option.
The “ifelse” block is used to evaluate trading conditions. If the condition is true, the blocks under “then” will be executed. If the condition is false, the blocks under “else” will be executed.
Use the suggestion feature to add the Moving Average Indicator.
Set the MA period to 9 and “Bars Ago” to 1.
“Bars Ago” is identifies the bar used to get the Moving Average value. “Bars Ago” equals to 1 means Get the Moving Average value from one bar before the current bar.
Add another Moving Average block to complete the trading condition. This time use the
In plain English, the EA logic in the image can be read like this:
Run the EA once per bar. If Moving Average with period 9 is higher than Moving Average with period 18 then Buy 0.1 lots, with a take profit of 100 pips, a stop loss and trailing stops of 50 pips.
But if the condition is false (Moving Average with period 9 is not higher than Moving Average with period 18) Sell 0.1 lots.
The same EA can be built using two trading conditions:
Please note that the EA does not have any blocks to close positions. If you are not
hedging a new Buy order closes all existing short positions before it is executed. A new Sell order closes all existing long positions before it is executed. If you hedge, you need to use the Close long and Close short blocks.
The Simple MA EA is not an MA Crossover EA, it is a simple EA that uses a simple condition. An MA Crossover uses complex trading conditions. Please see the section Complex Trading Conditions to learn how to create crossovers.
G
ENERATING THE
EA
FOR
M
ETA
T
RADER
After you finish your EA, click on the MQL4 icon. A new window opens showing the EA Code. You can also generate the EA Code using the View Code option in the MQL Code menu.
In the Displaying code window you have three options:
-Copy to Clipboard, so you can use the Paste option in any window application.
-Create the Expert Advisor for MetaTrader, this option saves the EA code (mq4 file) and the compiled EA (ex4 file). MetaTrader uses the compiled EA to trade. Keep in mind this option works if you set up the MetaTrader directory and the MetaTrader Expert folder.
E
XPERT
A
DVISOR
V
ARIABLES
Variables are important because you can use them to change EA parameters without having to re generate the EA. You also need them to optimize the Expert Advisor.
To add variables to your Moving Average EA, click on the Add variables icon. Select a name and type for the variable.
A new variable is created and new variable blocks are available on the left panel. “Integer MA PeriodSlow” is used to create the variable and assign an initial value. This block is added automatically to the center panel.
“get value MAPeriodSlow” block means that the variable value is used instead of a
defined fixed number.
“set value MAPeriodSlow” block sets a new value to the variable. “reset value MAPeriodSlow” block resets the variable to the initial value.
Set the variable initial value to 18. Use the suggestion feature to replace the period block 18 with “get value MAPeriodSlow”.
Now generate the EA again. In MetaTrader, attach the EA to a chart. Check the EA
Inputs: The EA now contains variables for the MA periods. Now, you can change the periods directly in MetaTrader. You can also optimize the MA periods during backtesting to find combinations that improves profitability.
Common Variables
All Expert Advisors created with My EA Builder have the following predefined variables in MetaTrader:
-UseFiveDigits: You can use 5 or 4 digit brokers. If UseFiveDigits = true, your broker uses 5 digits.
-isECN: If true, you are using an ECN broker so orders are opened and later Take Profit and Stop Loss are added.
-AllowHedge: You can set your EA to hedge. If AllowHedge=true your EA will hedge. By default generated EAs do not hedge (AllowHedge is set to false). If you do not hedge the EA closes all BUYs (long positions) before executing a SELL (short position); it also closes all SELLs (short positions) before executing a BUY (long position).
-Slippage: Minimum slippage for trade execution. -MagicNumber: EA's magic number or EA's ID.
C
OMPLEX
T
RADING
C
ONDITIONS
Trading conditions can be more complex when mixing technical indicators, pricing and volume with logical comparisons. My EA Builder has the “AND”, and “OR” blocks to create logical comparisons.
The “AND” comparison block is true if both inputs are true. The “OR” comparison block is true if at least one input is true. These blocks should be used in cases where two or more comparisons are needed.
For example you want to trade if MA Period 9 > MA Period 18 AND ADX > 30. You need both conditions to be true to trade. In this case you need to use the “AND” block
Creating an MA Crossover
There are many ways to define an MA Crossover. Here we will use the simplest form. An MA Crossover to Buy takes place if:
-MA Fast Period of 9 in bar 2 <= MA Slow Period of 18 in bar 2 AND -MA Fast Period of 9 in bar 1 > MA Slow Period of 18 in bar 1 So the indicator crosses and changes direction from bar 2 to bar 1
You can also define the MA Crossover using nested "if" (this is equivalent to an “AND” since both conditions need to be true to trade.
M
ULTI
T
IMEFRAME
M
ULTI
C
URRENCY
EA
S
To create a multi timeframe EA, select the desired timeframe from “Timeframe”. The
following image shows and EA that goes long if MA Period 9 > MA period 18 in the 5 minute chart and MA Period 9 > MA period 18 in the 15 minute time frame.
To create a multi currency EAs, select the desired currency from “Pair”. The following EA trades two pairs EURUSD and USDCAD using simple MA conditions.
If your EA is not multi timeframe always use Current Timeframe
If your EA is not multi currency always use Current Symbol
U
SING
C
USTOM
I
NDICATORS
You can use any well-written custom indicator in My EA Builder. You only need to define the indicator info using this format:
“Indicator Name”, parameter 1, parameter 2, etc
The Custom Indicator block is used to generate the iCustom MQL command. ICustom is
the MQL command to use custom indicators. It uses several inputs, for example: iCustom("EURUSD", PERIOD_M1, "EAName",12,10,1,0)
iCustom parameters:
-Symbol or pair: “EURUSD”
-Timeframe: PERIOD_M1 means 1-minute chart or timeframe -Custom Indicator Name: “EA Name”
-Custom Indicator Parameters: Separated by commas: 12,10 An example for indicator parameters is the indicator period.
-Signal number or Mode: Each indicator can have up to 8 signals. When using the indicator you need to define the signal you want from 0 to 7. In the example 1, means get the second signal from all available signals in the custom indicator (0 is the first signal). Keep in mind that some indicators have one signal while others have more than one signal. Signals examples are MAIN, PLUSDI, and MINUSDI for ADX (The ADX indicator has 3 signals). If your indicator plots 5 lines, most likely it will have 5 signals. -Bar: Candle used to get the signals. 0 means current bar. 1 means previous bar
In the next version of My EA Builder, a Custom Indicator import option will be added that gets all parameters automatically.