ea tree mt4 user guide p a g e | 1 · services in forex, cfd, futures, as well as equity markets...
Post on 31-Jul-2020
3 Views
Preview:
TRANSCRIPT
EA Tree MT4 User Guide P a g e | 2
What is the Metatrader 4 platform?
MetaTrader 4 is a very powerful trading platform designed to arrange brokerage
services in Forex, CFD, Futures, as well as equity markets around the globe. It is
one of the most popular programming trading languages. The best part is that the
MetaTrader 4 platform, real time data, and the MQL 4 language are available to you
for free.
What is EA Tree?
EA Tree is a Metatrader 4 drag and drop expert advisor builder. It is a windows
application that runs locally on your computer. You can create complex MQL4 EAs
using a very easy to use graphical user interface.
There are two different products:
- EATree MT4 standard Edition V2.0 that supports the MQL4 language
- EATree MT5 standard Edition V2.0 that supports the MQL5 language
This user guide supports EATree MT4 standard Edition V2.0
In EA Tree, expert advisors are created by connecting boxes together. Boxes may contain MQL functions, technical indicators, custom indicators, or values. Outputs of one box may be connected to inputs of another box to form a “tree of boxes”. EA Tree generates MQL code from the “tree of boxes” and then uses the MetaTrader 4 platform installed on your computer to convert the MQL code into an executable Expert Advisor.
EA Tree MT4 User Guide P a g e | 3
Benefits of using EATree
• Easy to use and understand drag and drop graphical user interface
• You do not need programming background
• You can quickly learn MQL
• Privacy of your trading secrets. No need to share your ideas with
programmers.
• You decrease EA development time to minutes instead of days or months.
• You can develop complex MQL EAs with multiple currencies and multiple
timeframes.
• You can incorporate multiple trading strategies into one EA
• You easily reuse code by saving and loading diagrams (trees of boxes)
• You are still able to import MQL custom indicators
• You create correct MetaTrader MQL code every time
EA Tree MT4 User Guide P a g e | 4
Contents
Quick Start: Creating a Simple EA
1. Basic Concepts
a. The concept of the “box”
b. Input and output buttons
c. Info Dialog Window
d. Connection between boxes
e. Box help
2. The “trade” box
a. Open Long (Buy)
b. Open Short (Sell)
c. Close Long
d. Close Short
e. Trading parameters
3. Logic Boxes
a. If-Else logic box
b. Crossover logic box
c. AND logic box
d. OR logic box
4. Technical Indicators Boxes
a. MACD technical indicator box
b. MA technical indicator box
5. Custom Indicators
Importing MQL custom indicators
6. Time Series Boxes
a. iOpen, iHigh, etc.
7. Function Boxes
a. Conversion Functions
b. Math Functions
8. Operator Boxes
a. Operators
9. Layout management
a. New Layout
b. Open Layout
c. Import Layout
d. Save Layout
e. Save Layout As
EA Tree MT4 User Guide P a g e | 5
10. MQL EA code generation
a. Exporting MQL EA source code file
b. Viewing MQL EA source code
Edit Menu: deleting a box
11. Tutorials:
a. Moving Average Crossover EA Tutorial
b. MACD EA Tutorial
12. Color Schemes
EA Tree MT4 User Guide P a g e | 6
Quick Start: Creating a simple EA
In this simple tutorial, you will create a simple EA layout in EATree then view the
MQL code and save it.
Buy condition: if MACD main indicator line is larger than its signal at previous bar
Sell condition: if MACD main indicator line is smaller than its signal at previous bar
Click on the Trade button on the toolbar, then click on the middle area of the new
Trade box and move it to the right.
EA Tree MT4 User Guide P a g e | 7
Click on the condition (If-Else button) on the toolbar, click on the middle area
of the new condition (If-Else) box and move it to the top middle of the
screen, then click on the T output button of the condition box and drag a connection
line to the openLong input button of the trade box making a connection. Also
connect the F output button of the condition box and drag a connection line to the
openShort input button of the trade box making a connection.
EA Tree MT4 User Guide P a g e | 8
Go to the Indicators menu and select MACD box, click on the middle area of the new
MACD box and move it to the left of the screen, then click on the M1 (Main1) output
button of the MACD box and drag a connection line to the A input button of the
condition box making a connection. Also connect the S1 (Signal1) button of the
MACD box and drag a connection line to the A input button of the condition box
making a connection. Right-click on the middle of the MACD box and select “Show
all input buttons”.
Select File->View MQL4 EA menu item to view the MQL4 code of the EATree layout
you have just created.
Select File->Save as MQL4 EA menu item to Save the MQL4 code of the EATree
layout. The default location directory is "C:\Program Files\MetaTrader 4".
You can set the MetaTrader 4 (MT4) directory by selecting File->Set Directories
menu.
In the next few sections, we will go over the basic concepts of EATree.
1. Basic Concepts
EA Tree MT4 User Guide P a g e | 9
The concept of the “box” and “buttons”
Boxes are a representation of information in EATree. They may contain technical
indicator, mathematical function, etc. Each box has input buttons and output
buttons. In this example, the Add box has three input buttons labeled A, B, and C
and one output button labeled O (Out). Each box has a unique label using its name
followed by an index. In this example the label Add_4 indicates that the box name is
Add and its index is 4, which means that it was the fourth box created in a layout of
boxes.
When you double click on the middle of a box, you will see its info dialog window.
For each button of the box the info dialog window lists the following:
EA Tree MT4 User Guide P a g e | 10
1. Button label
2. Button data type: double, int, string, boolean (bool), etc.
3. Button value
4. New button (variable) name: when generating MQL code, by default, button
will have the unique identifier of box label and button label for example
Add_4_A refers to a button labeled A in a box labeled Add_4. Setting a New
button (variable) name will override Add_4_A with your text, for example,
lots.
5. “Add to EA input variables”: activating this button will make this button
(variable) listed as expert advisor (EA) input variables, which makes it easier
to optimize this value in the MetaTrader 4 platform.
To remove a box, select the box then select Edit->Cut.
Connecting buttons:
Output buttons of one box can be connected to input buttons of another box if they
have the same data types, e.g. they are both “double” data type.
For example, to connect the O(OUT) button of the Add_4 box to the A input button
of the Condition_6 box, click on the O button and drag a rubber-band line, and
release it on top of the A button. To remove a connection, right-click on a button
and select “Disconnect All”.
Please note that buttons have different colors depending on their data types. In the
above example double data types are yellow, bool data types (True) are blue, bool
data types (False) are red. Please also note that if you change the color scheme
EA Tree MT4 User Guide P a g e | 11
under the View menu, all layout colors will change, but buttons of the same data
types will still have the same colors.
Box help
When dragging your cursor on top of a box, you will view help info such as box
name, or what it does.
Visible and Hidden buttons:
Boxes input button are sometimes hidden to save desk layout space. To show input
buttons, simply do right-click on the middle of the box and select “show all input
buttons”. Please note that if one of the input buttons is connected, you will not be
able to show input buttons until you remove all connections to input buttons first.
To modify hidden buttons values, double click on the box to show its info dialog
window. Then you can modify the values of all input buttons including hidden ones.
EA Tree MT4 User Guide P a g e | 12
2. The “trade” box
The trade box is the main box in EATree. It has many input buttons and no output
button. Please note that any box code will not be generated unless connected to a
layout that includes a Trade box. Every time you update the EATree MT4 software,
and open a layout that you have created before, please make sure to replace the
trade box by a new one to avoid code generation errors.
To create a Trade box Click on the Trade button on the toolbar or select Trade-
>Trade menu item.
Visible and Hidden buttons:
“Trade” box is an exceptional case. It has a selection of input buttons always visible,
and the rest are hidden. The reason for that it has too many input buttons to show.
By default all input buttons of the trade box will show in the generated MQL4 EA as
extern (input) variables.
Trade box input buttons:
The followings are trade box input buttons names, their code name or the name that
will show up in the generated MT4 EA, data types, and description of what it does. If
EA Tree MT4 User Guide P a g e | 13
you do not set their values in EATree, you will have another chance in MetaTrader 4.
However, it would be best if you set all the values that you know in EATree so you
do not have to set them again in MetaTrader 4 every time you modify your EATree
layout and create a new MT4 EA.
Button name Code name
Data- Type
Description
Open and close flags
openLong m_longOpenFlag bool Open long condition, default is false
openShort m_shortOpenFlag bool Open short condition, default is false
closeLong m_longCloseFlag bool Close long condition, default is false
closeShort m_shortCloseFlag bool Close Short condition, default is false
Main variables
takeProfitLong takeProfitLong int Take Profit Long in Pips.
takeProfitShort takeProfitShort int Take Profit Short in Pips.
To have a symmetrical takeProfit (same value for both long and short) connect a Logic-> Integer box or Trade->TPSL box to both takeProfitLong and takeProfitShort. If you connect the output of the TPSL box to a takeProfit button, then the takeProfit value is taken from the TPSL box.
stopLossLong stopLossLong int Stop Loss Long in Pips
stopLossShort stopLossShort int Stop Loss Short in Pips
To have a symmetrical stopLoss (same value for both long and short) connect a Logic-> Integer box or Trade->TPSL box to both stopLossLong and stopLossShort. If you connect the output of the TPSL box to a stopLoss button, then the stopLoss value is taken from the TPSL box. So this would be a customized trailing effects. Therefore, if you connect the output of the TPSL box to stopLoss buttons, make sure to turn off EATree trailingStop by setting useTrailingStop (desribled below) to false. Otherwise, you will have two trailing stops going on at the same time.
trailingStopLong trailingStopLong int Trailing Stop Long in Pips
trailingStopShort trailingStopShort int Trailing Stop Short in Pips
Set useTrailingStop (desribled below) to true to use Trailing Stops and make sure that both stopLossLong and stopLossShort are not connected to a TPSL box. Make sure to select trailing stop type trailingStopType.
EA Tree MT4 User Guide P a g e | 14
lots lot double lots value
takeProfitMin takeProfitMin int Minimum Take Profit (Long or Short) in Pips.
takeProfitMax takeProfitMax int Maximum Take Profit (Long or Short) in Pips
stopLossMin stopLossMin int Minimum Stop Loss (Long or Short) in Pips
stopLossMax stopLossMax int Maximum Stop Loss (Long or Short) in Pips
The reason for having minimum and maximum values for takeProfit and stopLoss is because you can connect the output of TPSL box to these input button and the output may be too small or too large. Even if you are not connecting the takeProfit and stopLoss buttons, you want to review these min and max values to make sure that they are acceptable. For example, if you set takeProfitLong = 300 pips, you want to make sure that takeProfitMax is at least 300.
MM moneyManagement bool Money Management, not used at this time
Money Management
barExecution barExecution bool Is execution by bars?
enterAgain enterAgain bool
If exited in the same bar of entry: Enter again : Check for completed bars if CompletedBars mode is on, if There are no new bars so do not execute in this case
waitOppSig waitForOppositeSignal bool If exited a long with a loss enter another long or wait to enter short or vice versa
allowTrading allowTrading bool Allow trading?
allowBuy allowBuy bool Allow Buy trades?
allowSell allowSell bool Allow Sell trades?
pendingDist pendingDist int
Order type depending on the value of the pending distance: pendingDist 0: means market order (instant execution) >0: Distance for Stop orders < 0 Distance for Limit orders
SLautoAdjust stopLossAutoAdjust-
ment bool
Adjust SL to three times the minimum SL allowed? This will ignore the stopLoss values.
autoAdjLevel stopLossAdjustment-
Level int
Level to adjust SL to three times the minimum SL allowed
maxRisk maxRiskCondition bool Max risk condition mode
RiskRatio RiskRatio int If maxRiskCondition is true: RiskRatio=3 means that TakeProfit/StopLoss = 3
EA Tree MT4 User Guide P a g e | 15
toHaveTpSl toHaveTakeProfitAndS
topLoss bool
To have TP, SL, and TS, or not; If True: Include TP and Sl: order includes TP and SL; OR it is done on 2 steps, one step to open order, the other to modify it by setting TP, and SL
hideTpSl hideTakeProfitAndStop
Loss bool Hide TP, SL, and TS from broker
slippage slipPage int Minimum slippage accepted in Pips
magic magic int
Magic Number. Select 0, if you don't want to use it. If you use the EA on different pairs, you must use different magic number for each instant EA. For example let us assume that you have two EAs, you give them codes 100 and 110, and you assign 01 to EURUSD and 02 to GPBUSD, then you set magic as: First EA: For EURUSD: 10001 For GBPUSD: 10002 Second EA: For EURUSD: 11001 For GBPUSD: 11002 In MetaTrader you can turn comments on and you can view which EA is doing what. Therefore the magic value is the first step to mangae your portfolio of EAs!
usePercEquity usePercentOfEquity bool Use Percent of Equity
PercOfEquity percentOfEquity double Percent of Equity
useRedFactor useReductionFactor bool Use Decrease factor
RedFactor reductionFactor double Reduction Factor. for money management lot-(lot*losses/ReductionFactor)
Fix Factor
useFixFactor useFixFactor bool Uses a fix factor, if true the following will be on:
TPlevel1 takeProfitLevel1 int TP No 1 in Pips
percentLot1 percentLot1 int Percent of lots No 1
TPlevel2 takeProfitLevel2 int TP No 2 in Pips
percentLot2 percentLot2 int Percent of lots
TPlevel3 takeProfitLevel3 int
TP No 3, Lots - all the rest, for example, if you use 50% in step1 and 25% in step2, then you use 100-75=25% in step3
EA Tree MT4 User Guide P a g e | 16
Warnings and alerts
showWarnings showWarnings bool Show Warnings/Alerts
sendAlerts sendAlerts bool Send Alerts
sendMail sendMail bool Send EMails
playSound playSound bool Play Sound
soundFile soundFile string Sound file to play
Hedging
allowHedging allowHedging bool hedging on/off
closeAtOppSig closeAtOppositeSignal bool close At Opposite Signal
Martingale
martinMode martinMode bool Martingale on/off
multAfterLoss multiplierAfterLoss double Martingale Multiplier increases the lot size after a loss
multAfterProfit multiplierAfterProfit double Martingale Multiplier increases the lot size after a profit
maxPosOnePair maxPositionsOnePair int Set Max number of positions for one currency pair
maxLotOnePair maxLotOnePair double Set Max number of lots for one currency pair
maxPosAll maxPositionsAllPair int Set Max number of positions for all currency pair
maxLotAll maxLotAllPair double Set Max number of lots for all currency pair
Miscelanous
maxOrderRetry maxOrderRetry int Max order retry: if there is an error: how many times to try to send the order
buyColor buyColor color Buy Color
sellColor sellColor color Sell Color
Time
useTradeTime useTradingTime bool Use Trading Time: on or off
timeZone1 timeZone1 string Time Zone No 1, time of the format "startHour:startMin-endHour:endMin" for example "02-06"
timeZone2 timeZone2 string Time Zone No 2, time of the format "startHour:startMin-endHour:endMin" for example "08:30-19"
timeZone3 timeZone3 string Time Zone No 3, time of the format "startHour:startMin-endHour:endMin" for example "20-23"
closeNotTime closeNotTime bool close all opened positions when not in Time zone
useFriEndTime useFridayEndTime bool Do not trade on Friday after certain time
FridayEndTime FridayEndTime string Time to stop trading on Friday, time of the format Hour:Min for example "21:45"
tradeOnMon tradeOnMonday bool Trade on Monday?
tradeOnTue tradeOnTuesday bool Trade on Tuesday?
tradeOnWed tradeOnWednesday bool Trade on Wednesday?
tradeOnThu tradeOnThursday bool Trade on Thursday?
tradeOnFri tradeOnFriday bool Trade on Friday?
EA Tree MT4 User Guide P a g e | 17
closeAtTime closeAtTime bool Close at a certain time after entering (entry time + period)?
closeAfterPrd closeAfterPeriod int Period (minutes)
Trailing Stop
TSbarExec checkTrailingStopBarE
xecution bool
Check trailing stops every tick regardless of Execution Mode (Bars or ticks)?
useTrailingStop useTrailingStop bool
If true, turn trailing stops on. If false, turn trailing stops off. Make sure that both stopLossLong and stopLossShort are not connected to a TPSL box. Make sure also to select trailing stop type trailingStopType.
trailingStopType trailingStopType
trailing Stop Type which can be one of these type: 1 = Trail immediately 2 = Wait to trail 3 = Uses 3 levels before trail 4 = Breakeven + Lockin 5 = Step trail 6 = EMA trail 7 = pSAR trail
timeBasedTS timeBasedTrailingStop bool time based trailing stop?
timeTSmin timeBasedTrailingStop
Minutes int time based trailing stop (minutes)
Settings for Type 2: Wait to trail use trailingStopLong and trailingStophort values above
Settings for Type 3: Uses 3 levels before trail
firstMove firstMove double Type 3: first level pip gain
firstStopLoss firstStopLoss double Type 3: Move Stop to Breakeven
secondMove secondMove double Type 3: second level pip gain
secondStopLoss secondStopLoss double Type 3: Move stop to lock is profit
thirdMove thirdMove double Type 3: third level pip gain
trailingStop3 trailingStop3 double Type 3: Move stop and trail from there
Settings for Type 4: Breakeven + Lockin
breakEven breakEven double Type 4: break even
lockInPips lockInPips double Type 4: lockIn Pips
Settings for Type 5: Step trail
eTrailingStop eTrailingStop int eTrailing Stop
eTrailingStep eTrailingStep int eTrailing Step
Settings for Type 6: EMA trail
You can get a similar result if you connect MA box to the input of TPSL box and the output of TPSL box to stopLoss buttons and set useTrailingStop to false.
EMATimeFrame EMATimeFrame int EMA Time Frame
applied_price applied_price int EMA applied price
EMAPeriod EMAPeriod int EMA Period
EMAShift EMAShift int EMA Shift
EA Tree MT4 User Guide P a g e | 18
initialStop initialStop int Initial Stop
Settings for Type 7: pSAR trail
You can get a similar result if you connect SAR (Parabolic Stop and Reverse System) box to the input of TPSL box and the output of TPSL box to stopLoss buttons and set useTrailingStop to false.
stepParabolic stepParabolic Parabolic SAR Step Parabolic
maxParabolic maxParabolic Max Parabolic
Highest-Lowest Line
findHiLo findHighestLowest bool Find highest high (and lowest low)in a certain time range
timeRangeHiLo timeRangeHighLow string
time range for Highest-Lowest, time of the format "startHour:startMin-endHour:endMin" for example "13:00-16:00"
Other
closeBySignalOnlyIfProfitable
closeBySignalOnlyIfProfitable
bool
close By Signal Only If Profitable. Set it to true if you have a close long or close short condition but you want it to be executed only if position is profitable.
EA Tree MT4 User Guide P a g e | 19
3. Logic Boxes
Logic boxes are important to connect between trade box condition buttons:
openLong, openShort, closeLong, and closeShort and the rest of the boxes in the
layout. All logic boxes are under the Logic Menu.
Condition (If-Else) logic box
The Condition (If-Else) box has this logic:
If A operator B then T (output button) is true else F (output button) is true.
Where operator could be equal to, not equal to, less than, greater than, etc.
For example:
If previous Stochastic Main indicator line M1 is larger than its previous Signal line S1
then T is true else (otherwise) F is true.
EA Tree MT4 User Guide P a g e | 20
Right-click on the middle of the Stochastic box and select “Show all input buttons”.
Please note that the “shift” input button value of the Stochastic box is 1, indicating
previous bar:
EA Tree MT4 User Guide P a g e | 21
Logic Condition in a time range (Loop) box:
Logic Condition in a time range (Loop) box is used to check if certain condition is
met within a time range, e.g. five bars. It also returns the last bar number at which
this condition last happened.
Let us assume that the operator oper is “larger than”. Logic Condition in a time
range (Loop) box will have this logic:
If A is larger than B is true at least once in a time range from start bars ago to end
bars ago then T is true, otherwise T is false (default value). Please note that the
output button W stores the last bar number at which this condition is true, for
example, 2 means 2 bars ago.
For example:
If A is connected to the M1 output of RSI box that has maPeriod of 14, Oper is
“Larger than”, B has a value of 50, start is 1 and end is 10, the logic here is that:
If within the last 10 bars, RSI(14) happened to be larger than 50 for at least once,
then T is true. If the last time this happened was 3 bars ago, then W output will
store the value of 3. Please note that the shift value at RSI box is ignored as it was
overwritten by the range from start to end.
EA Tree MT4 User Guide P a g e | 22
Crossover logic box
The Crossover box has this logic:
If A operator1 B AND C operator2 D then T (output button) is true else F (output
button) is true.
Where operator1 and operator2 could be equal to, not equal to, less than, greater
than, etc.
In this example we have this logic:
If Stochastic main M1 in previous bar> Stochastic signal S1 in previous bar
and
If Stochastic main two bars ago M2 < Stochastic signal two bars ago S2
Then T is true
Otherwise (else) is true
Please note that the “shift” input button value of the Stochastic box is 1, indicating
previous bar. So M1 and S1 output buttons refer to values at previous bar and M2
and S2 output buttons refer to Main and signal values two bars ago (shift + 1 =
1+1=2).
EA Tree MT4 User Guide P a g e | 23
Logic Crossover in a time range (Loop) box:
Logic Condition in a time range (Loop) box is used to check if certain crossover
occurred within a time range, e.g. ten bars. It also returns the last bar number at
which this Crossover last happened.
Let us assume that oper1 is (larger than) and Opert2 is (smaller than). The logic
here is: if A > B and C < D is true at least once in a time range from start bars ago
to end bars ago then T is true, otherwise T is false (default value), W will returns the
bar number at which this crossover happened last, for example, 4 means 4 bars ago.
For example: If A is connected to the M1 output of RSI box that has maPeriod of 14, Oper1 is “Larger than”, B is connected to the output of a Double box, where its input A has the value of 50. C is connected to the M2 output of the RSI box, Oper2 is “less than”, D is connected to the output of a the Double box, and start is 1 and end is 10, the logic here is that: If within the last 10 bars, RSI(14) happened to crossover 50 for at least once, then T is true. If the last time this happened was 3 bars ago, then W output will store the value of 3. Please note that the shift value at RSI box is ignored as it was overwritten by the range from start to end. Please note that M2 is always one bar before M1. For example, if M1 represents RSI(14) 3 bars ago, then M2 represents RSI(14) 3+1=4 bars ago. The Double box is used to store the value of 50 only once, so we optimize only one variable in MetaTrader.
EA Tree MT4 User Guide P a g e | 24
AND logic boxes
The AND box has this logic:
If (A AND B AND C AND D) then O (output button) is true
There are two AND boxes ANDL or ANDLong and ANDS or ANDShort. The two boxes
have that same exact logic, only different colors.
The following example shows that the ANDL box is used to connect the Long or Buy
condition to the openLong input button of the Trade box. While the ANDS box is
used to connect the Short or Sell condition to the openShort input button of the
Trade box.
EA Tree MT4 User Guide P a g e | 25
How do we get a buy signal?
In the example below, the C and D input buttons of ANDL_6 box are not connected.
But their default values are true as shown in the info dialog window.
The logic at box ANDL_6 is:
If (A AND B AND C AND D) then O (output button) is true
A is equal to Crossover_2_T (The T output of the Crossover_2 box)
B is equal to Condition_4_T (The T output of the Condition_4 box)
C is always true (default value, because it is not connected)
D is always true (default value, because it is not connected)
Therefore we need BOTH Crossover_2_T and Condition_4_T to be true in order for
ANDL_6_O, the output of the ANDL_6 box to be true and therefore we get openLong
(buy signal).
We use opposite logic for openShort (Sell signal) as shown in the red lines.
EA Tree MT4 User Guide P a g e | 26
OR logic box
The OR box has this logic:
If (A OR B OR C OR D) then OUT (output button) is true
There are two OR boxes OrL or OrLong and OrS or OrShort. The two boxes have
that same exact logic, only different colors.
The following example shows that the OrL box is used to connect the Long or Buy
condition to the openLong input button of the Trade box. While the OrS box is used
to connect the Short or Sell condition to the openShort input button of the Trade
box.
EA Tree MT4 User Guide P a g e | 27
How do we get a buy signal?
In the example below, the C and D input buttons of OrL_6 box are not connected.
But there default values are false as shown in the info dialog window.
The logic at box OrL_10 is:
If (A OR B OR C OR D) then O (output button) is true
A is equal to Crossover_2_T (The T output of the Crossover_2 box)
B is equal to Condition_4_T (The T output of the Condition_4 box)
C is always false (default value, because it is not connected)
D is always false (default value, because it is not connected)
Therefore we need only one of the two values: Crossover_2_T and Condition_4_T to
be true in order for ANDL_6_O, the output of the ANDL_6 box to be true and
therefore we get openLong (buy signal).
We use opposite logic for openShort (Sell signal) as shown in the red lines.
EA Tree MT4 User Guide P a g e | 28
Score box:
The score box gives a numerical output if the condition is true. This is useful if you
need a numerical result. Its cond input is Boolean type (true or false) that is usually
connected to a Boolean output such as that of the Condition box. The score input
stores the value that you want it to be the output. For example, If cond is connected
to the output T of a condition box and score input is 1, then the logic here is: If
cond is true then the output O equals to 1 otherwise the output O is zero.
For example if you have 3 conditions and you will open a long position if 2 out of the
3 conditions are true. In this case, you use an add box to add the outputs of 3 score
boxes. Then you use a condition box to test if the output of add is greater than or
equal to 2. This will also allow the possibility of adding weights to each condition and
open a trade only if a certain threshold (Sum of weights) is met.
EA Tree MT4 User Guide P a g e | 29
Level box:
Multiply the level value by the symbol adjusted point. The representation is in
decimal form. For example: 10 pips in EURUSD will be 0.0010 or 0.00100, so you
put 10 in the value input button of Level and the output of Level would be 0.0010.
For USDJPY, 10 pips will be 0.10 or 0.100. So you put 10 in the value button of Level
and the output of Level would be 0.10.
For example, if we have this logic: If the closing price of previous bar is greater than
the MA(20) plus 10 pips. First, we need to have an add box to add the outputs of
MA(20) and Level. The input of level is 10, so if we use EURUSD, it output will be
0.0010. We connect the output of iClose to the A input of the condition box and the
output of the Add box to the B input of the Condition box. Please note that the
default value of shift input in the MA and iClose boxes is 1, previous bar. Please note
also that Add always take three inputs that has a default value of zero, so the third
unused input button C value is zero.
EA Tree MT4 User Guide P a g e | 30
Double box:
A user defined Double value (decimal number), e.g. 10.5, useful to connect to
several Double values, so you optimize in MetaTrader only once.
In this example, two input variables of two Score boxes are connected to the output
of a Double box. The input of the Double_1 box value is 1.0. When you double click
on the Double_1 box, you can change the name of the A input variable to
“score_value” instead of Double_1_A, the name that you will see in MetaTrader.
When you select the “Add to EA input variables” button, it will become an input
variable in the MeatTrader EA and therefore you can modify its value or optimize it.
In short, instead of optimizing two input variables of the Score boxes, you are
optimizing only one.
EA Tree MT4 User Guide P a g e | 31
Integer box (Int):
A user defined Integer value, e.g. 7, useful to connect to several Integer values, so
you optimize in MetaTrader only once.
In this example, three input variables of three indicator boxes are connected to the
output of a Int (Integer) box. The input of the Int_4 box value is 14. When you
double click on the Int_4 box, you can change the name of the A input variable to
“indicator_period” instead of Int_4_A, the name that you will see in MetaTrader.
When you select the “Add to EA input variables” button, it will become an input
variable in the MeatTrader EA and therefore you can modify its value or optimize it.
In short, instead of optimizing three input variables of the Indicator boxes, you are
optimizing only one.
EA Tree MT4 User Guide P a g e | 32
String box:
A user defined String value, e.g. “EURUSD”.
Boolean box (Bool):
A user defined boolean (true or false) value, e.g. “false”.
4. Technical Indicators Boxes
There are many technical indicators listed under the Indicators menu such as the
MACD and MA (Moving average) technical indicator boxes
The MACD technical indicator box
Select Indicators->MACD, then right-click on the middle of the MACD box and select
“Show all input buttons”.
The MA (Moving Average) technical indicator box
EA Tree MT4 User Guide P a g e | 33
Select Indicators->MA, then right-click on the middle of the MA box and select
“Show all input buttons”.
Visible and Hidden buttons:
As described before, indicator boxes’ input buttons are hidden to save desk layout
space. To show input buttons, simply do right-click on the middle of the box and
select “show all input buttons”. Please note that if one of the input buttons is
connected, you will not be able to show input buttons until you remove all
connections to input buttons first.
To modify hidden buttons values, double click on the box to show its info dialog
window. Then you can modify the values of all input buttons including hidden ones.
Indicator Output Buttons:
Output buttons labels ending with “1” refer to the index at the shift input button. For
example if shift=1, then M1 is the Main indicator line at previous bar. Output buttons
labels ending with “2” refer to the index at the shift input button plus one. For
example if shift=1, then M2 is the Main indicator line at shift of 1+1=2 which is two
bars ago.
5. Custom Indicators
Using the custom indicator box, you can load any valid MT4 custom indicators source
file “.mq4”. Hit Custom Indicators->Import MT4 Custom Indicator menu item and
select a custom indicators source file “.mq4”. to create a new iCustom box. Right
click on the box and select “Show all input buttons” and double click on the box to
open its dialogue window.
EA Tree MT4 User Guide P a g e | 34
Input buttons:
Symbol: the symbol used, default is NULL to use chart symbol
Period: timeframe, default is zero to use current timeframe
Name: Name of the custom indicator without the “.mq4” extension. This input
button is included here in case of rare chance that the parser was not able to list the
custom indicator correctly. It can also be used as a workaround if the source file
“.mq4” is not available but the executable indicator “.ex4” is available.
Following the Name input button there will be input variables extracted from the
custom indicators source files. They are named in4, in5, etc. In the example above,
the input variable in4 has a value of 0.02 and a new variable name “Step”. The
name “Step” is actually the name of the variable extracted from the custom
indicator. But why was this button named in4 instead of “Step”. The reason is that a
variable could have very long names or it could have names that may not be valid. If
you move the mouse over an input button, you will see detailed info about it. Please
note that by default, all input variables, in1, in2, etc are added to the final EA’s input
variables.
Shift: last input button. It is the shift value of the indicator. Where a shift of 1
means previous bar, and 2 means the bar before and so on.
Output buttons:
Output buttons have labels such as O1, O2, etc. Please note that custom indicator
output buffers may not have names or may have names that are not valid, e.g.
having spaces. To find out original names of output buttons, move your mouse over
an output button. If there are no original names available, you will see “O1 output
button”, etc.
EA Tree MT4 User Guide P a g e | 35
Example of using custom indicators:
In MetaTrader 4, attach both the Ichimoku and MA indicators to the chart and open
the View->Data Window. Using the Data window, you can write down your trading
rules. For example:
If Chinkou Span of Ichimoku (Green) is crossing above MA(50) (thick blue) then
open long
If Chinkou Span of Ichimoku (Green) is crossing down MA(50) (thick blue) then open
short
In EATree, select Custom Indicators->Import MT4 Custom Indicator. Then in the
indicators folder (e.g. C:\Program Files\MetaTrader 4\experts\indicators folder)
select “Ichimoku.mq4” source file. This creates the box in the figure below. Then
add an MA box and change it maPeriod to 50 and add a condition boxes. Move your
mouse over the output buttons of the Ichimoku to find out which one is “Chinkou
Span”. Connect the button O5 to the A input of the condition box and connect the
M1 output of the MA box by the B input of the condition box as shown below.
Now we have this logic:
EA Tree MT4 User Guide P a g e | 36
If Chinkou Span of Ichimoku (previous bar) is greater than MA(50) (previous bar)
Please note that while custom indicator outputs are relating to one shift value, e.g. 1
or previous bar, outputs of technical indicators are relating to two shift values, e.g. 1
(previous bar) and 1+1=2 (two bars ago) such as M1 and M2 in this example.
Select Custom Indicators->Import MT4 Custom Indicator. Then select
“Ichimoku.mq4” to create another Ichimoku box “iCustom_3” in this example and
create another condition box “Condition_5”. Connect the O5 output of iCustom_3
box to the A input of Condition_5 box and the M2 output of the MA_2 box to the B
input of the Condition_5 box. Change the oper (Operator) of Condition_5 to “<”
(less than).
Now we have this logic:
EA Tree MT4 User Guide P a g e | 37
If Chinkou Span of Ichimoku (two bars ago) is greater than MA(50) (two bars ago)
So, our logic so far is:
If Chinkou Span of Ichimoku is crossing above MA(50)
Connect the T outputs of the two condition boxes to inputs of a new AndL box and
the two F outputs of the two condition boxes to inputs of a new AndS box. Finally
connect the output of the AndL box to the openLong input of a new Trade box and
the output of the AndS box to the openShort input of the Trade box.
Save the EA layout using File->Save Layout as and Save the MQL4 file using File-
>Save as MQL4 EA. Then open the new MQL4 EA file in MetaEditor 4, and compile
it. Optimize your EA settings in MetaTrader 4 and use your EA.
6. Time Series Boxes
Time Series Boxes such as iOpen, iHigh, iLow, or iClose are under the Time Series
Boxes Menu. For example, to get an iopen Time Series box, select Time Series-
>iopen then right-click on the middle of the iopen box and select “Show all input
buttons”.
EA Tree MT4 User Guide P a g e | 38
iOpen
It returns Open value for the bar of indicated symbol with timeframe (period) and
shift. If shift is 1, then it returns the open value of previous bar.
iHigh
It returns High value for the bar of indicated symbol with timeframe (period) and
shift. If shift is 1, then it returns the high value of previous bar.
iLow
It returns Low value for the bar of indicated symbol with timeframe (period) and
shift. If shift is 1, then it returns the low value of previous bar.
iClose
It returns Close value for the bar of indicated symbol with timeframe (period) and
shift. If shift is 1, then it returns the close value of previous bar.
iVolume
It returns volume value for the bar of indicated symbol with timeframe (period) and
shift. If shift is 1, then it returns the volume value of previous bar.
Ask
The latest known seller's price (ask price) for the current symbol. Please note that
using this function may not give accurate results in back-testing in MetaTrader.
Bid
EA Tree MT4 User Guide P a g e | 39
The latest known buyer's price (offer price, bid price) for the current symbol. Please
note that using this function may not give accurate results in back-testing in
MetaTrader.
HighestHigh
This function finds Highest High value in the range from start to end previous bars.
For example if start is 5 and end is 20, then it returns the highest value of a high in
that range.
LowestLow
This function finds Lowest Low value in the range from start to end previous bars.
For example if start is 5 and end is 20, then it returns the lowest value of a low in
that range.
In this example, the logic is:
If the high of previous bar is greater than or equal to the highest high of previous 10
bars then we open long. To open short, we check if the low of previous bar is less
than or equal the lowest low of previous 10 bars.
7. Function Boxes
There are several types of function boxes under the Functions Menu: conversion
functions and math functions.
Conversion Functions
EA Tree MT4 User Guide P a g e | 40
Conversion functions are very important because many buttons (variables) have
different data types, e.g. double, int, string, etc. buttons of different data types
cannot be connected and their data types have to be converted first. The most used
conversion functions are IntegerToDouble and DoubleToInt functions.
IntegerToDouble Conversion Function
It takes an integer type input A and converts it into double type output O. For
example if A=9 then O=9.0.
Please note that this function does not change the value but it allows connecting an
integer output to double input as in this example.
DoubleToInteger Conversion Function
It takes a double type input A and converts it into integer type output O. It uses the
MQL MathRound. So it rounds the double value to the nearest integer.
EA Tree MT4 User Guide P a g e | 41
For example if A=0.9 then O=1
If A= 0.3 then O=zero
And If A = -0.99999 then O=1
Indicators of Indicators!
In the following example, the output of RSI indicator is multiplied by a factor = 0.2
so the values are ranging between 0 and 20 instead of 0 to 100. Then using the
DoubleToInt box it is converted to an integer type. This is connected to the period
input of two indicator boxes: Stochastics and Momentum. So these indicators’s
periods are changing from bar to bar based on the RSI output values. So now we
have indicators of indicators!
Math Functions
There are many math functions such as Abs, Max, Min, Floor, etc.
EA Tree MT4 User Guide P a g e | 42
8. Operator Boxes
Under the Operators menu, there are Arithmetic Operators such as the Add,
Subtract, and Multiply operators.
9. Layout management
Layout is the hierarchy of boxes or tree of boxes. Tools to manage the layout are
available under the File menu or the left of the toolbar.
You can set the EATree and MT4 directories by selecting File->Set Directories menu
EA Tree MT4 User Guide P a g e | 43
New Layout
Clear the screen and start a new layout
Open Layout
Clear the screen and open an existing layout
Import Layout
Insert an existing layout. It is very useful when inserting a subtree of boxes that is
used often.
Save Layout
Save a layout in the EATree Layout “ly4” format. Do not enter the “.ly4” file
extension.
Save Layout As
Save a layout in the EATree Layout “ly4” format in a new name. Do not enter the
“.ly4” file extension.
If you have both EATree MT4 and EATree MT5, please note that EATree MT5 uses
the format “ly5” and the old format “lay”. Please avoid opening a file with “ly5” or
“lay” extensions as this will result in an incorrect MT4 EA and you will get errors
when you compile your EA in MetaEditor.exe.
10. MQL EA code generation and viewing
Tools to generate MQL code are available under the File menu or the toolbar. You
can set the EATree and MT4 directories by selecting File->Set Directories menu
EA Tree MT4 User Guide P a g e | 44
Select File->View MQL4 EA menu item to view the MQL4 code of the EATree
layout you have just created.
Select File->Save as MQL4 EA menu item to Save the MQL4 code of the EATree
layout. Do not add the “.mq4” file extension. The default location directory is
"C:\Program Files\MetaTrader 4" you can change it using File->Set Directories menu
so that our EA will be saved in the correct folder.
Once you have saved your MQL4 EA, you need to open the MT4 MetaEditor, double
click on your EA to open it, then hit “compile” to create executable EA “.ex4” that
you can use in MT4 platform.
Edit Menu:
Under Edit Menu, you can cut and select all boxes.
To delete a box, simply select it and choose Edit->cut or Ctr-X
11. Tutorials: Creating sample EAs
In this section, let us use some of the tools covered in this user guide to create
sample EAs. First we will create a Moving Average Crossover EA then we will create
a MACD EA.
EA Tree MT4 User Guide P a g e | 45
A. Moving Average Crossover EA Tutorial
First, let us list the EA rules.
Entry Rules:
Open Long:
previous MA(8) >= previous MA(13) and
MA(8) two bars ago < MA(13) two bars ago
Open Short:
previous MA(8) < previous MA(13) and
MA(8) two bars ago >= MA(13) two bars ago
Exit Rules:
Close Long: same rules as Open Short
Close Short: same rules as Open Long
We will use default trade box. Let us get started:
1. Create a MA box MA_1 using Indicators-> Moving Average. Double click
on the middle of the MA_1 box to open its info dialog window. Modify
maPeriod button value to 8 and select it to be an input variable in the MQL4
EA that we will generate by clicking on “Add to EA input variables”. Make sure
that shift button value is 1. Close the info dialog window.
2. Create another MA box MA_2 using Indicators-> Moving Average. Double
click on the middle of the MA_2 box to open its info dialog window. Modify
maPeriod button value to 13 and select it to be an input variable in the MQL4
EA that we will generate by clicking on “Add to EA input variables”. Make sure
that shift button value is 1. Close the info dialog window.
EA Tree MT4 User Guide P a g e | 46
3. Create Condition box Condition_3 using Logic->Condition. Connect the M1
output button of the MA_1 box to the A button of the Condition_3 box and
the M1 output button of the MA_2 box to the B button of the Condition_3
box. Double click on the middle of the Condition_3 box to open its info dialog
window. Modify Oper (Operator) to “>=” and close the info dialog window.
EA Tree MT4 User Guide P a g e | 47
Now we have this logic at Condition_3 box:
If A is larger than or equal to B then T is true, otherwise F is true
Since A = M1 of (MA_1) and B = M1 of (MA_2) this logic is equivalent to:
If previous MA(8) is larger than or equal to previous MA(13) then T is true,
otherwise F is true.
Please note that since the shift button value of MA_1 box is 1, then M1 refers
to Moving Average base (main) indicator line at previous bar. Same concept
applies to MA_2 box.
4. Create Condition box Condition_4 using Logic->Condition. Connect the M2
output button of the MA_2 box to the A button of the Condition_4 box and
the M2 output button of the MA_2 box to the B button of the Condition_4
EA Tree MT4 User Guide P a g e | 48
box. Double click on the middle of the Condition_4 box to open its info dialog
window. Modify Oper (Operator) to “<” and close the info dialog window.
Now we have this logic at Condition_4 box:
If A is smaller than B then T is true, otherwise F is true
Since A = M2 of (MA_1) and B = M2 of (MA_2) this logic is equivalent to:
If MA(8) two bars ago is smaller than MA(13) two bars ago then T is true,
otherwise F is true.
Please note that since the shift button value of MA_1 box is 1, then M2 refers
to Moving Average base (main) indicator line two bar ago (shift
value+1=1+1=2). Same concept applies to MA_2 box.
5. Create an AndL box AandL_5 using Logic->AndL. Connect its input button A to the T output button of the Condition_3 box and connect its input button B to the T output button of the Condition_4 box.
EA Tree MT4 User Guide P a g e | 49
The AndL box is a group of conditions to open long trade. The logic at AndL_5 box is: If (A and B and C and D) are true then the output O is true, otherwise it is false. So all of the input buttons’ values have to be true in order for O to be true. A is equivalent to T output of Condition_3 box B is equivalent to T output of Condition_4 box C is not connected, so it is true (default value) D is also not connected, so it is true (default value) So, the logic at AandL_5 box is equivalent to: If previous MA(8) is greater than or equal to previous MA(13) and If MA(8) two bars ago is smaller than MA(13) two bars ago Then the output O is true, otherwise (if at least one of the conditions is false) O is false.
6. Create an AndS box AandL_6 using Logic->AndS. Connect its input button A to the F output button of the Condition_3 box and connect its input button B to the F output button of the Condition_4 box.
EA Tree MT4 User Guide P a g e | 50
The AndS box is a group of conditions to open short trade. The logic at AandL_6 box is: If (A and B and C and D) are true then the output O is true, otherwise it is false. So all of the input buttons’ values have to be true in order for O to be true. A is equivalent to F output of Condition_3 box B is equivalent to F output of Condition_4 box C is not connected, so it is true (default value) D is also not connected, so it is true (default value) So, the logic at AndL_6 box is equivalent to: If previous MA(8) is smaller than previous MA(13) and If MA(8) two bars ago is larger than or equal to MA(13) two bars ago Then the output O is true, otherwise (if at least one of the conditions is false) O is false.
7. Create a Trade box Trade_7 using Trade->Trade. Connect its openLong
input button to the output of AndL_5 box, O. Connect its openShort input
button to the output of AndS_6 box, O. Now entry rules are satisfied:
Open Long:
previous MA(8) >= previous MA(13) and
EA Tree MT4 User Guide P a g e | 51
MA(8) two bars ago < MA(13) two bars ago
Open Short:
previous MA(8) < previous MA(13) and
MA(8) two bars ago >= MA(13) two bars ago
8. Connect the CloseLong input button to the output of AndS_6 box, O and
connect the CloseShort input button to the output of AndL_5 box, O.
Now exit rules are satisfied:
Close Long: same rules as Open Short
Close Short: same rules as Open Long
9. Save the MQL4 file using File->Save as MQL4 EA. Then open the new
MQL4 EA file in MetaEditor 4, and compile it.
EA Tree MT4 User Guide P a g e | 52
10. Optimize your EA settings in MetaTrader 4 and use your EA.
B. MACD EA Tutorial
First, let us list the EA rules.
Entry Rules:
EA Tree MT4 User Guide P a g e | 53
Open Long:
1. previous MACD main > previous MACD signal and
2. MACD main two bars ago< MACD signal two bars ago and
3. Previous EMA (20) > two bars ago EMA (20)
Open Short:
1. previous MACD main < previous MACD signal and
2. MACD main two bars ago> MACD signal two bars ago and
3. Previous EMA (20) < two bars ago EMA (20)
Exit Rules:
Close Long: same rules as Open Short
Close Short: same rules as Open Long
We will use default trade box
Let us get started:
11. Create trade box using Trade->Trade, and move it to the right of the screen
12. Create an ANDL box using Logic->AndL and connect its output O to the
openLong button of the Trade box
EA Tree MT4 User Guide P a g e | 54
13. Create a Crossover box using Logic-> Crossover and connect its T (true)
output button to the A button of the AndL box.
14. Create a MACD box using Indicators-> MACD, then right-click on the
middle of the MACD box and select “Show all input buttons”, then connect:
its Main output button M1 to the A button of the Crossover box,
its Signal output button S1 to the B button of the Crossover box,
EA Tree MT4 User Guide P a g e | 55
its Main output button M2 to the C button of the Crossover box, and
its Signal output button S2 to the D button of the Crossover box.
The logic here is:
If previous MACD main M1> previous MACD signal S1 and
MACD main two bars ago M2< MACD signal two bars ago S2
15. Create a MA box using Indicators-> Moving Average. Right-click on the
middle of the MA box and select “Show all input buttons”.
EA Tree MT4 User Guide P a g e | 56
16. Create Condition box using Logic->Condition. Connect the Main output
button of the MA box M1 to the A button of the Condition box and Main
output button of the MA box M2 to the B button of the Condition box.
17. Connect the O output of condition box to the B button of the AndL box.
The subtree for the openLong condition is now complete with these three
conditions:
1. previous MACD main > previous MACD signal and
2. MACD main two bars ago< MACD signal two bars ago and
3. Previous EMA (20) > two bars ago EMA (20)
18. Create an AndS box using Logic->AndS and connect its output button to the
openShort button of the trade box.
EA Tree MT4 User Guide P a g e | 57
19. Since the openShort logic is the opposite of that of the openLong, connect the
F (false) output button of the Crossover box to the A button of the new AndS
box. Also, connect the F (false) output button of the Condition box to the B
button of the new AndS box.
20. To get exit signals, connect the O variable of the AndL box to the closeShort
button of the Trade box and the O variable of the AndS box to the closeLong
button of the Trade box.
EA Tree MT4 User Guide P a g e | 58
21. Double click on both MACD and MA boxes and select a number of variables to
be input variables in the MQL4 EA that we will generate by clicking on “Add to
EA input variables”.
22. The layout is now complete.
23. Save the Layout using File->Save Layout As.
EA Tree MT4 User Guide P a g e | 59
24. If you are using EATree MT5 standard Edition V2.0
save the MQL5 file using File->Save as MQL5 EA. Then open the new
MQL5 EA file in MetaEditor 5, and compile it.
save the MQL4 file using File->Save as MQL4 EA. Then open the new
MQL4 EA file in MetaEditor 4, and compile it.
Finally, we optimize selected input variables in MetaTrader 4 tester using
EURUSD H1 timeframe from Jan. 1, 2011 to Oct. 1, 2011 with no money
management. We have used: TakeProfit = 100, StopLoss = 35, MACDfast =
20, MACDslow = 22, MACDsignal = 7, MAperiod = 20.
EA Tree MT4 User Guide P a g e | 60
12. Color Schemes
EA Tree MT4 User Guide P a g e | 61
Under View menu there are several color schemes that are created not just to make
your layout look “pretty”, but also to make it creating EA layouts a much easier
process. You can select your favorite color scheme while you are using EATree:
1. "Avant" Color Scheme
The default color scheme which is used mostly in this user guide so far.
2. "Fizz" Color Scheme
3. "He Can" Color Scheme with connection line width of 2
EA Tree MT4 User Guide P a g e | 62
4. "Robo" Color Scheme with connection line width of 2
EA Tree MT4 User Guide P a g e | 63
5. "Wheels of Fire" Color Scheme
6. "Details" Color Scheme with connection line width of 2
7. "Autumn Leaves" Color Scheme with white background
EA Tree MT4 User Guide P a g e | 64
8. "Tangerine Skies" Color Scheme
We wish you successful trading!
Disclaimer: For testing and evaluation purposes only. In no event will authors be liable for any
damages whatsoever.
top related