Skip to content

Build an EA with EA Builder Pro

If you came here because you’re starting the endeavour of building a trading robot (EA), you’ve come to the right place! This tutorial builds an EA with EA Builder Pro. Follow us in our footsteps to build our example EA, or make your own decisions with the extra information this tutorial gives you.

In short:

  • You build the ‘Cowabunga’ EA: a trend filter on the H4 timeframe, with entries on the M15 timeframe.
  • Step by step: indicators, the four signals (with groups and calculations) and two Pro modules.
  • It’s an advanced EA: you’ll learn enough to build advanced EAs yourself.

When trading, you place orders at a broker. A broker usually offers a trading platform to send orders manually; one of the best is MetaTrader. Besides manual trading, MetaTrader lets you install a trading robot, called an “Expert Advisor” (EA). EA Builder Pro helps you build an EA with the greatest of ease.

This tutorial assumes you’ve got MetaTrader 4 or 5 installed and are fairly familiar with it. If you’re not, start with Get everything you need: it guides you to installing MetaTrader and running your first EA. Then come back to this page.

This tutorial builds an advanced EA, and can feel quite complex. Prefer an easier start?

Let’s get started! In this tutorial we create the famous ‘Cowabunga’ EA. It uses the trend on the H4 (4 hour) timeframe as a filter, and looks at the M15 timeframe for opportunities to go long or short.

First we write down the entries and exits. We call them ‘Signals’: a collection of conditions for entries and exits.

Open Buy: the trend is up on the H4 timeframe:

  • the 5-bar EMA is above the 10-bar EMA;
  • RSI is above 50;
  • Stochastic is moving up, but is not overbought.

And there is an entry opportunity on the M15 timeframe:

  • MACD crosses up the 0 value, or
  • MACD is negative but just started going up.

Open Sell: the opposite. The trend is down on H4 (the 5-bar EMA under the 10-bar EMA, RSI below 50, Stochastic moving down but not oversold), and on M15 MACD crosses down the 0 value, or is positive but just started going down.

Close (for buy and sell):

  • Target the next 50- or 00 price level. If a buy order opens at 1.09887, the target is 1.10000: 11.3 pips up.
  • If that level is less than 5 pips away, use another target: the distance between the open price and the Parabolic SAR. If Parabolic SAR is 10 pips under the open price, the target is 10 pips above the open price.
  • The stop loss is the value of Parabolic SAR, when SAR is below the open price (for a buy order).

That’s quite something! The EA you have in mind may be less complicated: 9 out of 10 trading strategies are. But this tutorial shows EA Builder Pro can create advanced EAs, and teaches you enough to create them yourself.

  1. Open our webtool. Check the platform button in the app bar: your EA gets that platform, MT4 or MT5. Not sure which one? Read MT4 or MT5, which is best?
  2. Click + Add Expert Advisor.
  3. Choose Blank: we build the EA from scratch, so there is nothing to remove first. (A template is a working example EA, to see how a complete EA works.)
  4. Name the EA ‘Cowabunga’ and click Add Expert Advisor.

Your EA opens in the EA editor, in four parts: Indicators, Signals, Strategy and Money Management. See The EA editor. We start with the first part: Indicators.

Indicators give the EA the information it needs to decide when to open and close an order.

  • You add indicators to your EA’s list. The list is the one place your EA gets this information from.
  • When you change an indicator’s parameters, every condition that uses this indicator changes with it.
  • To use an indicator twice with different values, add it twice with a different name. For example ‘EMA 5’ with Period 5 and ‘EMA 10’ with Period 10.

To add an indicator:

  1. Click Add indicator in the Indicators column.
  2. Choose the indicator, for example Moving Average. All standard MetaTrader indicators are there; your own custom indicators too.
  3. Give it a name and set its parameters. They are the same parameters MetaTrader shows when you add the indicator to a chart.
  4. Click Save.

Add these indicators (parameters not mentioned keep their default value):

NameIndicatorTimeframeParameters
EMA 5Moving AverageH4Period 5, Method Exponential, Apply to Close
EMA 10Moving AverageH4Period 10, Method Exponential, Apply to Close
StochasticStochastic OscillatorH4%K period 10, %D period 3, Slowing 3, Method Simple, Price field Low/High
RSIRelative Strength IndexH4Period 9, Apply to Close
MACDMACDCurrent timeframeFast EMA 12, Slow EMA 26, MACD SMA 9, Apply to Close
PSARParabolic SARCurrent timeframeStep 0.02, Maximum 0.2

MACD and PSAR use the timeframe the EA runs on: M15 for this strategy.

Indicators column with EMA 10, EMA 5, MACD, PSAR, RSI and StochasticIndicators column with EMA 10, EMA 5, MACD, PSAR, RSI and Stochastic
The six indicators of the Cowabunga EA.

See Add an indicator to your EA for all the options.

Want to use your own custom indicators? See Upload a custom indicator.

With the indicators added, your EA doesn’t open or close any orders yet: you only made the indicators known to your EA. Now you create the signals: the conditions that decide when the EA opens and closes orders.

The 4 signals:

  • Open Buy: when it becomes true, your EA opens (enters) a buy order.
  • Open Sell: when it becomes true, your EA opens a sell order.
  • Close Buy: when it is true, your EA closes (exits) its buy orders.
  • Close Sell: when it is true, your EA closes its sell orders.

Click Open Buy in the Signals column. With a blank EA, the signal has no conditions yet. Build it like this:

1. The 5-bar EMA is above the 10-bar EMA: compare the indicator with another indicator, with the Above operator: EMA 5 | S0 > EMA 10 | S0.

S0 is the Shift (Bar): which bar the EA looks at. 0 is the current bar, 1 the previous bar, and so on. See Shift (Bar).

2. RSI is above 50: compare the indicator with a value. Switch the right operand to Constant and enter 50: RSI | S0 > 50.

3. Stochastic is moving up, but not overbought: two conditions.

  • Moving up: the current value is above the previous value: Stochastic | S0 > Stochastic | S1.
  • Not overbought: below 80: Stochastic | S0 < 80.

4. MACD crosses up 0, or MACD is negative but just started going up: only one of the two has to be true, so add a group set to ANY, with:

  • MACD | S0 Up Cross 0;
  • a second group set to ALL (every condition has to be true): MACD | S0 < 0, MACD | S0 > MACD | S1 and MACD | S1 <= MACD | S2: below 0, going up now, after going down between the two bars before.

Add conditions and groups with + at the top of a group. Use Move up and Move down in a condition’s menu to put them in a logical order.

Open Buy signal with ALL: EMA 5 above EMA 10, RSI above 50, Stochastic S0 above S1, Stochastic below 80, and an ANY group with MACD Up Cross 0 or an ALL group of three MACD conditionsOpen Buy signal with ALL: EMA 5 above EMA 10, RSI above 50, Stochastic S0 above S1, Stochastic below 80, and an ANY group with MACD Up Cross 0 or an ALL group of three MACD conditions
Open Buy: the trend filter on H4 and the MACD entry on M15, with an ANY group and an ALL group in it.

Click Save. See Signals and conditions for all the options.

  1. Export the EA, and place it in the Experts folder of MetaTrader. See Run your first EA.
  2. Run the EA in MetaTrader’s Strategy Tester with Visual mode on.
  3. Pause the backtest the moment an order opens, and check that the conditions were met.

Always check in Visual mode, and at the moment the order opens: a condition on the current bar (Shift 0) uses a bar that is still forming. Look later, and the indicator’s value may have moved in the meantime.

The opposite of Open Buy: Below instead of Above, 20 instead of 80 for Stochastic, Down Cross for MACD, and MACD positive but just started going down.

Open Sell signal with ALL: EMA 5 below EMA 10, RSI below 50, Stochastic S0 below S1, Stochastic above 20, and an ANY group with MACD Down Cross 0 or an ALL group of three MACD conditionsOpen Sell signal with ALL: EMA 5 below EMA 10, RSI below 50, Stochastic S0 below S1, Stochastic above 20, and an ANY group with MACD Down Cross 0 or an ALL group of three MACD conditions
Open Sell: the opposite of Open Buy.

Remember we said this tutorial would be advanced? Here we go. Feeling overwhelmed? Try first, take a rest if it helps, and come back later: it’s a learning experience that pays off in the long term.

The close strategy: target the next 50- or 00 price level, but only if it is more than 5 pips away. (Otherwise a module sets the target, later in this tutorial.) That gives 2 conditions, both ALL:

1. The next price level is more than 5 pips away. Calculate the remainder of the order’s open price divided by the distance between price levels, 50 pips, with the Modulo (%) operator. For an open price of 1.09887: 1.09887 % 0.00500 = 0.00387, so 38.7 pips past the last level. If the remainder is less than 45 pips, the next level is more than 5 pips away:

Open price % 50 * Pip < 45 * Pip

2. The price has passed the next price level. The distance to the next level is 50 pips minus the remainder. Close the buy order when Bid is above the open price plus that distance:

Bid > Open price + (50 * Pip − (Open price % 50 * Pip))

In our example: 1.09887 + (0.00500 − 0.00387) = 1.10000. The order closes when the price has risen 11.3 pips.

Close Buy signal with ALL: Open price Modulo 50 times Pip Below 45 times Pip, and Bid Above Open price Add 50 times Pip Subtract Open price Modulo 50 times PipClose Buy signal with ALL: Open price Modulo 50 times Pip Below 45 times Pip, and Bid Above Open price Add 50 times Pip Subtract Open price Modulo 50 times Pip
Close Buy: the next price level is more than 5 pips away, and Bid has passed it.

Use Add Advanced Condition for a condition with a calculation: see Add Advanced Condition.

The same signal as Close Buy, but the opposite: the remainder is more than 5 pips, and Ask is below the open price minus the remainder.

Close Sell signal with ALL: Open price Modulo 50 times Pip Above 5 times Pip, and Ask Below Open price Subtract Open price Modulo 50 times PipClose Sell signal with ALL: Open price Modulo 50 times Pip Above 5 times Pip, and Ask Below Open price Subtract Open price Modulo 50 times Pip
Close Sell: the opposite of Close Buy.

Your EA now has its Open and Close signals, so it already trades automatically. But there’s more: modules change the behaviour of your EA.

Two tasks remain:

  • The alternative take profit, when the next price level is less than 5 pips away: the distance to PSAR.
  • The stop loss: the value of PSAR.

For this we add Take profit - Conditional (Pro) and Stop loss - Conditional (Pro), each twice: once for buy and once for sell. These modules need a Pro subscription.

  1. Click Add module in the Strategy column.
  2. Choose the module, for example Take profit - Conditional (Pro). The help next to the form explains every setting.
  3. Fill in the settings (below) and click Save.

For buy orders:

  • Name: Buy TP
  • Enabled for: Buy orders
  • Precondition, ALL:
    • PSAR is below the open price, so the price is going up: PSAR | S0 < Open price;
    • the next price level is less than 5 pips away: Open price % 50 * Pip >= 45 * Pip.
  • TP start value: the open price plus the distance to PSAR: Open price + (Open price − PSAR | S0)
  • When to remove TP: empty
  • TP offset (pips): 0, Trail step size: 0, Close percentage: 100

For sell orders, add the module again:

  • Name: Sell TP, Enabled for: Sell orders
  • Precondition: PSAR | S0 > Open price, and Open price % 50 * Pip <= 5 * Pip
  • TP start value: Open price − (PSAR | S0 − Open price)

For buy orders:

  • Name: Buy SL
  • Enabled for: Buy orders
  • Precondition: PSAR is below the open price: PSAR | S0 < Open price
  • SL start value: PSAR | S0
  • When to remove SL: empty
  • SL offset (pips): 0, Trail step size: 0, Trail minimum distance (pips): 1, Close percentage: 100

For sell orders: Name Sell SL, Enabled for Sell orders, Precondition PSAR | S0 > Open price, and the same SL start value PSAR | S0.

Strategy column with Stop loss - Conditional (Pro) Buy SL and Sell SL, Take profit - Conditional (Pro) Buy TP and Sell TP, and Open order V3 with hedging disabledStrategy column with Stop loss - Conditional (Pro) Buy SL and Sell SL, Take profit - Conditional (Pro) Buy TP and Sell TP, and Open order V3 with hedging disabled
The Strategy column: two stop loss and two take profit modules, and Open order V3.

See Strategy Modules for all modules. You’ll be surprised how flexible they are: for example, How to set stop loss based on the ATR indicator?

You’ve now completed your first fully working EA! Export it and use it in MetaTrader: see Run your first EA.

Our advice for the next steps:

  • Backtest: in the cloud with Run backtest, or in MetaTrader with Visual mode, to confirm that orders open and close when you expect. See Run a backtest.
  • Compare: not sure you followed every step? Compare your EA with the template Cowabunga MT5 EA (or MT4).
  • Ask: need help configuring your EA? Subscribe and contact us with your questions: we answer with examples until you’ve met your goal.
  • Tune: improve the settings of your EA. On the free plan, change them in EA Builder Pro; with Pro, the exported EA has inputs, which you can also optimize in MetaTrader.
  • Demo first: run the EA on a demo account until you’re sure it works as expected, preferably on a VPS. About a week is generally not long enough: we verify at least 200 orders manually and run the EA for at least 3 months on a demo account before we go live.

Thank you for sticking with us through this tutorial, and we hope to keep seeing you around!

MetaTrader is a registered trademark of MetaQuotes Ltd. EA Builder Pro is not affiliated with MetaQuotes.