My EA Builder 1.1 User Guide COPYRIGHT 2014. MyEABuilder.com. MetaTrader is a trademark of MetaQuotes www.metaquotes.net.
Table of Contents MAIN FEATURES... 3 PC REQUIREMENTS... 3 INSTALLATION... 4 METATRADER SETUP... 4 MY EA BUILDER 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 USING CUSTOM INDICATORS... 20 My EA Builder User Guide 2
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. MAIN FEATURES 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 REQUIREMENTS My EA Builder needs: -A Windows computer -Java from java.com -MetaTrader My EA Builder User Guide 3
INSTALLATION -Install java from http://java.com -Install My EA Builder METATRADER SETUP 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 To setup the MetaTrader directory, Click on the Set MetaTrader option and select the directory where mql.exe is located. My EA Builder User Guide 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) To find your Data Folder open MetaTrader and go to File menu Click on Open Data Folder My EA Builder User Guide 5
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. MY EA BUILDER GRAPHICAL USER INTERFACE GUI My EA Builder is really easy to use. Drag and drop components from the left into the center panel. Make sure all components are connected. After you define your EA logic, click on the MQL4 icon to generate the Expert Advisor. My EA Builder User Guide 6
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 MOVING AVERAGE 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. In the image, the green line is the fast moving average. The red line is the slow moving average. My EA Builder User Guide 7
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. My EA Builder User Guide 8
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. A basic trading condition is made comparing blocks. You can use Technical Indicators, numbers, price, and volume in the comparison. Using the suggestion feature click on the first comparison block. My EA Builder User Guide 9
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. Bars Ago equals to 0 means Get the Moving Average value from the current bar. My EA Builder User Guide 10
Add another Moving Average block to complete the trading condition. This time use the left panel, click on Indicators and search for the Moving Average Indicator. Drag and drop the MA Indicator into the right input of the comparison block. Set the MA period to 18, and Bars Ago to 1. Using the suggestion feature under then, select the Buy block from the Trade option. Then follow the same procedure to add the Sell icon under else. Set the pair, lot size, take profit, stop loss, and trailing stops if any. Stops are set using pips so 100 means 100 pips. My EA Builder User Guide 11
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: My EA Builder User Guide 12
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. GENERATING THE EA FOR METATRADER 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: -Save as, so you can save the EA code as an mq4 file. You then need to compile the EA on your own to create the ex4 file (open the EA code file with MetaEditor and use the compile option or hit F5) My EA Builder User Guide 13
-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. EXPERT ADVISOR VARIABLES 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. My EA Builder User Guide 14
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. The EA end result is the same but you are now using a variable for the MA period. Repeat the same procedure for the other MA period. My EA Builder User Guide 15
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. -Positions: Controls the maximum number of open positions. For example, set it to 1 and your EA will only open 1 position per pair. My EA Builder User Guide 16
COMPLEX TRADING CONDITIONS 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 The "OR block is used if at least one of the conditions needs to be true to trade. My EA Builder User Guide 17
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. MULTI TIMEFRAME MULTI CURRENCY EAS In MT4 you can create multi timeframe, multi currency EAs. Unfortunately backtesting of multi currency EAs is not available in MT4 (You can backtest multi currency EAs in MT5). Multi timeframe backtesting in MT4 is possible but it is not straightforward. It may lead to errors if you do not make sure you have all price data for all timeframes used in the EA. My EA Builder User Guide 18
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. My EA Builder User Guide 19
If your EA is not multi timeframe always use Current Timeframe If your EA is not multi currency always use Current Symbol USING CUSTOM INDICATORS 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 My EA Builder User Guide 20
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. My EA Builder User Guide 21