How To Create Strategies

<< <%SKIN-STRTRANS-SYNTOC%> >>

Navigation:  Video Tutorial >

How To Create Strategies

menu_video Watch the video here.

 

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.

 

clip0221

 

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

 

clip0222

 

Add condition: Moving Average with period 5, crosses above, Moving Average with period 20.

 

clip0223

 

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:

 

clip0224

 

clip0225

 

Now the opposite to close the trade.

 

clip0226

 

clip0227

 

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.

 

clip0228

 

clip0229

 

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

 

clip0230

 

In Money Management, we will use a fixed size of 1 minilot or 0.1 standard lots.

 

clip0231

 

We can check Audible Alerts for Each Order and Error sending order.

 

clip0232

 

In Inputs, we will add the Trade Size.

 

clip0233

 

The Expert Advisor is ready and the source is generated.

 

clip0234

 

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

 

clip0235

 

clip0236

 

Now we want to backtest it to see how it works. View -> Strategy Tester.

 

clip0237

 

Select the Expert Advisor we just created. If it doesn't appear in the list, restart your platform.

 

clip0238

 

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

 

clip0239

 

clip0240

 

What we see here is that the order is opened and closed multiple times in the same place. That's not what we want!

 

clip0241

 

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

 

clip0242

 

...let's say 5 bars. And the Minimum Trade Duration 5 bars.

 

clip0243

 

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.

 

clip0244

 

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.

 

clip0245

 

clip0248

 

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

 

clip0246

 

clip0247

 

Create the opposite order.

 

clip0249

 

And we will do the same to close the trade.

 

clip0250

 

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

 

clip0251

 

clip0252

 

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.

 

clip0253

 

In the next video, we will start creating a more useful Expert Advisor based on daily breakouts.