You are on page 1of 17

In this tutorial, I'm going to show you a quick and easy way to create an Expert Advisor with EA Builder.

Our first Expert


Advisor will be based on a simple moving average crossover. We will cover some important issues while developing the
Expert Advisor.
 

 
Create a new MetaTrader 4 Strategy and call it MA Cross.
 

 
Add condition: Moving Average with period 5, crosses above, Moving Average with period 20.
 
 
It is important to notice the difference between is above and crosses above.
 
Is above is a continuous signal which means that the order would be opened every tick as long as the moving average
with period 5 is above the moving average with period 20. This would lead to many open trades.
 
Crosses above is an instant signal which means that the order will be opened just once at the crossover.
 
Click OK. Click this magic button to create the opposite conditions for sell order:
 

 
 
Now the opposite to close the trade.
 

 
 
Here you can choose either is below, or crosses below. Both are correct, because even if you choose the continuous
signal, once the trade is closed, there are no more trades to be closed. Click OK. Create the opposite order to close
short positions.
 

 
 
In the Common tab, there are some additional options we will look at later.
 

 
In Money Management, we will use a fixed size of 1 minilot or 0.1 standard lots.
 
 
We can check Audible Alerts for Each Order and Error sending order.
 

 
In Inputs, we will add the Trade Size.
 
 
The Expert Advisor is ready and the source is generated.
 

 
Copy the source and compile it (jump to another topic for explanation).
 
 

 
Now we want to backtest it to see how it works. View -> Strategy Tester.
 
 
Select the Expert Advisor we just created. If it doesn't appear in the list, restart your platform.
 

 
Select the EURUSD symbol, 15-minute time frame, Every Tick model, choose a date interval, check Visual mode and
start the tester.
 
 

 
What we see here is that the order is opened and closed multiple times in the same place. That's not what we want!
 
 
The problem is that as the price moves up and down, the moving averages cross upwards and downwards multiple
times inside a single bar. We will fix this by simply checking the option Next Open Trade After (in the Common tab)...
 

 
...let's say 5 bars. And the Minimum Trade Duration 5 bars.
 
 
The Expert Advisor will wait at least 5 bars before opening the next trade or before closing the open position. We can
run the tester again to see if it works. Copy the source, replace the old source and compile. Run the tester.
 

 
This time, we see one buy order at the moving average crossover, the order is closed at the next crossover, sell order is
opened, and so on.
 
Another option to deal with this is to send the order only when a new bar opens. Add condition: Bar Opens.
 
 

 
Because this signal is instant, we need to change the crosses above to is above.
 
 

 
Create the opposite order.
 
 
And we will do the same to close the trade.
 

 
We don't want to open a trade for every bar as long as the condition is met. Therefore we will limit the Maximum Open
Trades to 1 (uncheck two checkboxes and check one checkbox).
 
 

 
It will not open a new trade before the position is closed. Copy the source, replace the old source and compile. Now,
because we are sending orders only at the bar opening, we can use the fastest model - Open Prices Only.
 
 
In the next video, we will start creating a more useful Expert Advisor based on daily breakouts.
 

You might also like