Creating MQL5 Expert Advisors in minutes using EA Tree: Part One

eatree | 1 November, 2011


Introduction

EA Tree is the first drag and drop MetaTrader MQL5 Expert Advisor Builder. It is a windows application that runs locally on your computer. You can create complex MQL5 code using a very easy to use graphical user interface.

In EA Tree, Expert Advisors are created by connecting boxes together. Boxes may contain MQL5 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 MQL5 code from the "tree of boxes" and then uses the MetaTrader 5 platform installed on your computer to convert the MQL5 code into an executable Expert Advisor.

Figure 1. EA Tree Graphical User Interface

Figure 1. EA Tree Graphical User Interface


In the next few section, we will go over the basic concepts of EA Tree.

1. Basic Concepts

The concept of the "box" and "buttons".

Boxes are a representation of information in EA Tree. 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 ะก and one output button labeled OUT.

Each box has a unique label using its name followed by an index. In this example the label Add_1 indicates that the box name is Add and its index is 1, which means that it was the first box that was created in a layout of boxes.

Figure 2. Add box

Figure 2. Add box

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.

In this example, we connect the OUT button of the Add_2 box to the A button of the If_Else_1 box.

Figure 3. "Add" box + "if else" box

Figure 3. "Add" box + "If-Else" box

2. The "Trade" box

The Trade box is the main box in EA Tree. It has many input buttons. The most important buttons are the openLong, openShort, closeLong, and closeShort buttons. There are also many trading parameters.

 Figure 4. "Trade" box

Figure 4. "Trade" box

3. The "MM" (MoneyManagement) box

The MM box handles MoneyManagement in EA Tree. It has several input buttons. You need to connect its output button to the MM button of the Trade box.

Figure 5. "Trade" box + MM box

Figure 5. "Trade" box + MM box


4. 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.

If-Else logic box

The 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.

Figure 6. "If-Else" logic box

Figure 6. "If-Else" logic box

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. The shifts sets indexes of the indicators to connect to.

In this example we have this logic:

If current Stochastic main > current Stochastic signal and

If previous Stochastic main > previous Stochastic signal

Then T is true and F is false

Figure 7. Crossover + Stochastic Logic boxes

Figure 7. "Crossover" + "Stochastic" logic boxes

AND logic box

The AND box has this logic:

If (A AND B AND C AND D) then OUT(output button) is true

Figure 8. "And" box

OR logic box

The OR box has this logic:

If (A OR B OR C OR D) then OUT (output button) is true

Figure 9. "Or" box

Figure 9. "Or" box


5. Technical Indicators Boxes

There are many technical indicators listed under the Technical Indicators menu such as the MACD and Moving Average (MA) technical indicator boxes

The MACD technical indicator box

Figure 10. MACD technical indicator box

Figure 10. MACD technical indicator box

The MA (Moving Average) technical indicator box

Figure 11. MA (Moving Average) technical indicator box

Figure 11. MA (Moving Average) technical indicator box

6. Custom Indicators

Custom Indicators tools are available at the Custom Indicators Menu and the Toolbar. EA Tree uses only MQL5 custom indicators.

7. MQL5 Functions

EA Tree has many boxes for MQL5 functions including:

8. Tutorial: Creating a simple Expert Advisor

In this section, let us use some of the tools covered in this article to create a simple EA.

First, let us list the Expert Advisor trade rules.

Entry Rules:

Open Long:

  1. Current MACD main > current MACD signal and
  2. Previous MACD main < previous MACD signal and
  3. Current EMA(20) > previous EMA(20)

Open Short:

  1. Current MACD main < current MACD signal and
  2. Previous MACD main > previous MACD signal and
  3. Current EMA(20) < previous EMA(20)

Exit Rules:

Close Long: same rules as Open Short
Close Short: same rules as Open Long

We will use default trade box and no money management settings.

Let us get started:

1. Create a Trade box and create an AND box and connect its output to the openLong button of the Trade box:


Figure 12. Trade box + And Box

Figure 12. Trade box + And Box

2. Create a Crossover box using and connect its T(true) output button to the A button of the And box.

Figure 13. Trade box + And box + Crossover box

Figure 13. Trade box + And box + Crossover box

3. Create a MACD box using, connect its Main output button to the A and C buttons of the Crossover box, and connect its Signal output button to the B and D buttons of the Crossover box.

The logic here is:

If current MACD main > current MACD signal and
      
previous MACD main < previous MACD signal

Figure 14. Trade box + And box + Crossover box + MACD box

Figure 14. Trade box + And box + Crossover box + MACD box


4. Create a MA and If-Else boxes. Connect the Main output button of the MA box to the A and B buttons of the If-Else box. Connect the OUTPUT of IF-Else box to the B button of the AND box.

The subtree for the openLong condition is now complete with these three conditions:

  1. Current MACD main > current MACD signal and
  2. Previous MACD main < previous MACD signal and
  3. Current EMA(20) > previous EMA(20)

Figure 15. Trade box + And box + Crossover box + MACD box + MA box + If-else box

Figure 15. Trade box + And box + Crossover box + MACD box + MA box + If-else box

5. Create another And box and connect its output button to the openShort button of the trade box.

6. Since the openShort logic is the opposite of that of the openLong, connect the F output button of the Crossover box to the A button of the new And box. Also, connect the F output button of the If-Else box to the B button of the new And box:


 Figure 16. Trade box + And box + Crossover box + MACD box + MA box + If-else box + And box

Figure 16. Trade box + And box + Crossover box + MACD box + MA box + If-else box + And box

7. To get exit signals, connect the OUT variable of the first AND box to the closeLong button of the Trade box and the OUT variable of the second AND box to the closeShort button of the Trade box:

 Figure 17. Adding CloseShort to the Trade box
 Figure 17. Adding CloseShort to the Trade box

8. Double click on both MACD and MA boxes and select a number of variables to be input variables in the MQL5 EA that we will generate.

Figure 18. Input parameters

Figure 18. Input parameters

9. The layout is now complete. Save the Layout and save the MQL5 file. Then open the new MQL5 Expert Advisor file in MetaEditor 5 and compile it.

Figure 19. Generated Expert Advisor

Figure 19. Generated Expert Advisor

10. Finally, we optimize selected input variables in MetaTrader 5 Strategy Tester.


Figure 20. Testing of the Expert Advisor 

Figure 20. Testing of the Expert Advisor


Conclusion

There are many benefits of using EA Tree: