Previous page: Part 2 : Indicators.

Tutorial - Part 3: Signals

Last update: 22 April 2023

With the indicators added to your EA, your EA will not yet open or close any orders. You only made the indicators (and their parameters) known to your EA. So, next task will be to create the entry/ exit signals, which consists out of one or multiple condition(s), which define when the EA will open and close orders.

First, choose which signal you will be creating first. We strongly suggest you start by creating the 'Open Buy' signal and create the other signals when you've verified a buy order is opened at the correct moment. Only then, you should create the other signal(s). We suggest you do this, to keep the complexity of creating and adjusting signals as low as possible while you're still learning. We will do this now, so we start by creating the Open Buy entry signal.

The 4 types of signals are:

Open Buy; when this signal activates, your EA will open (enter) a buy order.
Open Sell; when this signal activates, your EA will open a sell order.
Close Buy; when this signal activates, your EA will close (exit) your buy order(s), unless the Open Buy signal is active at the exact same time.
Close Sell; when this signal activates, your EA will close your sell order(s), unless the Open Sell signal is active at the exact same time.

To create the Open Buy signal, click 'Open Buy' in your EA's main screen.

click open buy
Click the 'Open Buy' Signal of your EA.

If you've chosen the 'Empty template' in Part 1 (EA Builder Pro - Getting started) of this tutorial, then you'll now see an almost empty screen. This is because the signal is still without conditions. We're going to have to add the condition(s), which forms the Signal, ourselves.

You are probably seeing this:

an empty open buy signal
Clicking the menu Icon.

To start adding conditions, click the 'menu icon', which looks like 3 dark dots in a vertical position. Once you've clicked it, we're going to choose 'Condition' to add a condition. Repeat this step 3 more times, so that you've got 4 conditions added to the signal in total, which all look the same.

Remember our Open Buy signal from the Tutorial introduction page? Let's rephrase the Open buy signal:

  1. the 5-bar EMA is above the 10-bar EMA
  2. RSI is bigger than 50
  3. Stochastic is moving up, but not overbought
  4. MACD crosses up 0 or
  5. MACD is negative but just started going up

Now let's adjust the conditions we just created so that the conditions match the description of the first part of the Open Buy signal:

1. The 5-bar EMA is above the 10-bar EMA
To check if the EMA 5 indicator value is bigger (>) than the EMA 10 indicator value, we will compare the indicator to another indicator by using the 'bigger than' (>) operator.

The 5-bar EMA is above the 10-bar EMA
5-bar EMA is above the 10-bar EMA

This might be the first time you run into 'Shift (bar)'. The value entered at the bar's shift represents which bar (a.k.a. candle) the EA will evaluate. So if '0' is entered at the EMA 5's Shift (Bar), it means the EA will look at the current bar's EMA value. If '1' is entered, it will look at the pervious bar's EMA value, etc.

2. RSI is bigger than 50
To check if the RSI indicator value is bigger (>) than 50, we will compare the indicator to the value by using the 'bigger than' (>) operator. In order to select '50', you will first need to change the right part of the condition to 'Value' instead of 'Indicator'. Use the round button with arrow to do that and select 'Value' (more info).

RSI is bigger than 50
RSI is bigger than 50

3. Stochastic is moving up but not overbought
Here we have to use 2 conditions, one for checking if the indicator is moving up and one for checking if the indicator is not in the overbought area.

  • To check if the Stochastic indicator is moving up we need to compare the previous value of the indicator with the current value of the indicator. When the value is increasing, it is moving up. So, to check if the line is moving up, we need to check if the current value (shift 0) is bigger than (>) the previous value (shift 1).
  • To check if the Stochastic indicator is not in the overbought area we need to check if the indicator's value is below 80. We will do this by using the 'Smaller than' (<) operator.

Stochastic is moving up but not overbought
Stochastic is moving up but not overbought

4. MACD crosses up 0 or MACD is negative but just started going up
Now we're going to add another (the 5th) condition to our signal, but we will now choose 'Operator' and select 'Or'. Use the menu of the new 'Or' operator and add another condition and another operator. Select 'And'. Use the menu of the new 'And' operator and add 2 more Conditions. Great! You're getting the hang of it now!
So, here we have to use 2 conditions, but only one needs to be true, which is why we used the 'Or' operator. Also, the second condition are actually two conditions. For the second condition we use the 'And' operator to tell the EA that both conditions have to be true for the second condition to be true.

When adding conditions to your signal you can drag-and-drop the conditions to drag them to the right place.

Here's what you just created should look like:

MACD crosses 0 or starts going up
MACD crosses 0 or starts going up

We've now created the first signal. Now it's time to test the signal, so we're going to:

  1. Export the EA.
  2. Place the EA in the 'Experts' folder (which happens automatically in MT5 when double-clicking the downloaded file, for MT4 do this manually).
  3. Run the EA in MetaTrader's Tester in 'Visual mode'.
  4. Verify a Buy order was opened at the correct moment.

When verifying if the order was opened at the correct moment, always use a backtest in 'Visual mode'. This is necessary, because when using conditions on the current bar (Shift 0), the bar is still forming, which means that if you are trying to verify the order's open moment at a later time (and thus the bar already being formed or having progressed further), the indicator's value may have moved in the meanwhile. That's why you always need to pause the backtest the moment the order is opened.

Now that we've got the first Signal working, we'll also be creating the other signals:

Open Sell

open sell
The Open Sell signal

Close Buy

Remember I said on the starting page of this tutorial that this tutorial was going to be advanced? Well, here we go. If you soon feel overwhelmed, don't worry: try first, rest if this will help you and come back later. This is a learning experience which will come with results on the long term.
Let's reiterate on the close strategy: We're going to target 50- and 00 price levels if the next level is more than 5 pip away. Otherwise, we're going to set the target to the distance to the value of Parapolic SAR. We're also going to set a stop loss, for which we will use a stop loss module later on.
So, how are we going to do all that? We know that our close signal will exist out of 2 conditions:

  1. Distance to the next price level must be more than 5 pip away.
  2. Price must be higher than open price + distance to the next price level.

1. Distance to the next price level must be more than 5 pip away

To know how far away the next price level is, we have to calculate the remainder of the order's open price, devided by the price level's distance, which is 50 pips. When using arithmetic operators in our webtool, select the '%' (modulo) operator to calculate the remainder of a division. So when we calculate: 1.09887 (the open price) % 0.00500, the remainder is 0.00387 (38.7 pips). So if we can create a condition which checks if the remainder is less than 45 pips we know the distance to the next price level is more than 5 pips away.
Now, let's create the first condition:

Close Buy

close buy condition 1
The first condition of the Close Buy signal

2. Price must be higher than open price + distance to the next price level.

Now, because the first condition is set, the second condition will only be evaluated if the distance to the next price level is more then 5 pips away.
The second condition will check if the current price has passed the next price level. To do this, we have to check if the price is bigger than the order's open price + the distance to the next price level. The distance to the next price level can be calculated by substracting the remainder from 50 pips. So, the calculation is 50 pips - (open price % 50 pips) = amount of pips to the next price level. So, we close our buy order if the Bid price is bigger than the order's open price + (50 pips - (open price % 50 pips)).
In our example this translates to 1.09887 + (0.00500 - (1.09887 % 0.00500)) = 1.01000. So if the price rises 11.3 pips the order will be closed. Here's the condition to check if Bid is bigger than (>) open price + (50 pips - (open price % 50 pips)):

close buy condition 2
The second condition of the Close Buy signal

Pep talk

WOW! you've created the close buy signal! Wait... are you still here? Don't worry if you're still doing the calculations on paper to check all this and to try to understand. Also feel free to take a break when building EA's, it does take practise and often it feels like a puzzle, but you'll get better at it and before you realize you're building any EA you can imagine!

(Optional) You can copy/ paste signals or invert them, by using the menu icon to the right of the signal. Try it! It will speed up your EA building.

Close Sell

Here's the close signal for sell orders. It's basically the same signal as the signal for closing buy orders, but opposite.

close sell
The Close Sell signal

If you want to know more about Signals and what they're capable of, please check the in-dept Signals documentation.

You've now created the EA's Open- and Close signals, which means that your EA will already trade automatically. However, there's more. There are all kinds of ways to change the behaviour of your EA. These are the so called 'Modules' which we will also use for our EA.

Next: Part 4 : Modules.