How to use indicators in my EA?

Indicators are the input values for the signals and for some of the modules. Before you can use any indicators in your EA, you will first have to add these in the Indicator section. We advise you to give your indicators names that are easy to distinguish. By default we offer you all the standard MT4 and MT5 indicators, which you are probably already used to.

moving average indicator
Adding the Moving Average indicator

We've added a couple of predefined values, which are technically not indicators, but these can still be found at the indicator part of our platform: Open, Close, Low, High

Custom Indicators

Beside the standard Metatrader 4 and Metatrader 5 indicators you can upload your own indicators. These custom indicators can be downloaded for free or bought from third parties. If you have sufficient MQL knowledge you can also build your own indicator yourself and upload it.

Indicators
Duration: 17 minutes

There are 2 ways to upload a custom indicator:

  • Use the Upload button on the 'Add new Indicator' form.
  • Use Custom Indicator page.

Add a new Indicator

upload custom indicator
Add your custom indicator

Once you uploaded your indicator, you can select it at any time in the list of indicators. Custom indicators can be found at the bottom of the list.

Now you've uploaded your custom indicator. You've probably experimented with this indicator in MetaTrader, or you've been using it already. If not, please do so and get acquainted with your indicator. If so, we assume you know which input values you want to use and which ones are optional. However, there are 2 input values which are mandatory: the Mode and Shift parameters.

Mode

If your custom indicator has more than one possible output value (lines/ arrows/ etc.), it is important to retrieve the one you want to use in your EA. To find the correct Mode input value, you must investigate at which change of value you want to take action. There are 4 common options:

  • You're waiting for an object, like an arrow.
  • You're waiting for a colour-switch.
  • You're waiting for a line to cross a value.
  • You're waiting for a line to cross another line.
Arrows

As you know indicators can sometimes draw multiple arrows or lines. You probably use these in your manual (visual) trading feedback and decisions. Now that you continue to automate your strategy you want to select these arrows or lines as values. It's important to know a comprehensive indicator exists of multiple collections of arrows or lines, for example the up-arrows and the down-arrows. Both are maintained in their own list, called 'buffers'. What you need to do is select the correct buffer for your trading strategy and enter it in the 'Mode' input when adding the indicator to your EA. If you don't know this value yet, you can use the following strategy to get this Mode value: First, load your indicator in Metatrader. Example: let's assume you have this indicator:

custom indicator with arrows
Image 2. An arrows indicator. (1) Position/ time of the arrow. (2) Information regarding your Mode Input and indicator's value.

Note that the mouse pointer in the image above is at the up arrow. I have the Data Window open in Metatrader, as you can see on the left side of the screen. Also, you can see that the data window displays 2 rows (at the yellow icons). These are the 'buffers' that the indicator is giving us and which can be used. The rows have 2 columns. The first column shows the values the indicator gives at 20:15, one bar before the bar selected. The second column shows the values the indicator gives at 20:30. One of the two rows displays a value. It's the value of the price the up arrow is to.

This is all the information you need to automate an EA using this indicator, because you now know:

  1. The up arrow is at Mode 0, the Down arrow is at Mode 1
  2. The arrows appear when the indicator switches from having no value, to having any value. The actual value is irrelevant when the logic condition is setup correctly (as you will see in a bit). The moment when the arrow appears is also important, as you will understand in a minute when discussing Shift.

In order to use this indicator in our EA, we need to upload the indicator twice. Once for Mode 0, and once for Mode 1. Remember that every time you have an indicator which is showing multiple different outputs (arrows, lines, ...), you will also need to add the indicator multiple times for each value that you want to use. If you've got an indicator which shows 4 types of arrows (2 strong, 2 weak) and you want to use all 4 in your trading Signal, you will have to add the indicator 4 times. Make sure you all give them a distinguishing name, so they can be recognized easily. For example: 'Up strong', 'Up weak', 'Down strong' and 'Down weak'. Use short but clear names.

custom indicator with arrow up
Image 3. Custom Indicator 'Arrow Up' with Mode 0
custom indicator with arrow down
Image 4. Custom Indicator 'Arrow Down' with Mode 1

Notice that Shift value '1' was set. This was necessary because the indicator will always draw the arrow on the previous bar, not on the current bar. The only way to know this is by watching the indicator in backtest/ demo/ live and take note. If the arrow is drawn on the current bar, choose shift value '0'.

Next, the Signal has to be created. The Signal will make sure the order is opened when the arrow is displayed.

custom indicator in open buy signal
Signal Open Buy
custom indicator in open sell signal
Signal Open Sell

Take note that in the image above we're comparing the current bar and the previous bar with value '2147483647'. This value represents an 'empty value'. This is no longer necessary, you can simply leave the input on the right side empty. Think about the logic behind this. As you were able to see in image 2, the value of the indicator is empty when there is no arrow and the value is not empty when the arrow is drawn. That's why we check that the value of the previous bar is equal (==) to an 'empty value' and the value of the current bar is unequal (!=) to an 'empty value'.

That's it! Your EA is ready to Export and test.

If you want to switch between Buy and Sell at the moment the arrow changes direction, you will have to make sure your Open Buy signal is exactly equal to the Close Sell signal and the Open Sell signal is exactly equal to the Close Buy signal. You can use the Copy/ Paste options for this to be sure you don't make any mistakes.

Colour switch

As you know indicators can sometimes show a line which changes colour from red to blue (or any colour) and vice versa. You probably use these in your manual (visual) trading. Now that you want to automate your strategy you want to aim at these colour switches. It's important to learn that this type of indicator sometimes exists of one collection of values, each value representing the colour, but sometimes multiple collections: one collection per colour. These collections are called 'buffers'. What you need to do is find the correct buffer for your trading strategy and enter it in the 'Mode' input of your indicator. To get the correct value, you need to load your indicator in Metatrader. Let's assume you want to use this indicator:

custom indicator with colour
Image 5. A colour indicator. (1) Position/ time of the sell colour. (2) Information regarding your Mode Input and indicator's value.

Note that (1) is at the sell colour (red) in the image above. The Data Window is open in Metatrader, as you can see on the left side of the screen. Also, you can see that the Data Window displays 2 rows (at the yellow icons close to (2)). These are the 'buffers' that the indicator is giving and which can be used by your EA. The rows have 2 columns. The second column shows the values the indicator gives at (1), which is at 00:00. One of the two rows displays a value: the second row, which has label 'Value 2'. When you would move your mouse to the right, to the buy colour, you would see the first value is filled and the second value is empty.

This was all the information you need to automate an EA using this indicator, because you now know:

  1. Buy (blue) colour is Mode 0, Sell (red) colour is at Mode 1
  2. The colour appears when the indicator switches from having no value, to having any value. It's irrelevant which value the buffer gets, which you will understand in a bit.

In order to use this indicator in our EA, we need to upload the indicator twice. Once for Mode 0, and once for Mode 1. Remember that every time you have an indicator which is showing 2 different things, you will also need to add the indicator twice. If you've got an indicator which shows 3 types of arrows (red, grey, blue) and you want to use all 3 in your Signal, you will have to add the indicator 3 times. Make sure you all give them a proper name. It's also possible the colour indicator will only have 1 buffer and the value it gets is -1 or 1 (and additionally a value for grey, which you will notice when you look at the Data Window while hovering over the colour in the chart).

custom indicator colour blue
Image 6. Custom Indicator 'Colour Blue' with Mode 0
custom indicator colour red
Image 7. Custom Indicator 'Colour Red' with Mode 1

Next, the Signal has to be created. The Signal will make sure the order is opened when the colour is displayed.

custom indicator colour open buy
Signal Open Buy
custom indicator colour open sell
Signal Open Sell

Take note that in the image above we're comparing the current bar and the previous bar with value '2147483647'. This value represents an 'empty value'. This is no longer necessary, you can simply leave the input on the right side empty. Think about the logic behind this. As you were able to see in image 5, the value of the indicator is empty when the colour is not displayed and the value is not empty when the colour is displayed. That's why we check that the value of the previous bar is equal (==) to 'empty value' and the value of the current bar is unequal (!=) to 'empty value'.

That's it! Your EA is ready to Export and test.
While running the test I found out that the value switch isn't applied to the current bar by the indicator, but to the previous bar, so I had to change the Shift input for both custom indicators (Blue and Red) to value 1.

If you want to switch between Buy and Sell at the moment the colour changes every single time (instead of working with TP/ SL), you will have to make sure your Open Buy signal is exactly equal to the Close Sell signal and the Open Sell signal is exactly equal to the Close Buy signal.

You're waiting for a line to cross a value or
You're waiting for a line to cross another line

These types of indicator work exactly the same as the above indicators for adding arrows/ colour indicators for finding the correct Mode input. Also, you will add the indicator once for every line in the indicator you will want to use in your signal. The only difference is the Signal part, where you will have to check for a cross-over to occur. Creating a cross-over is explained at the Signals page.

Shift

By giving 'shift' value 0, you select the indicator's value at the current bar. value 1 represents the previous bar, 2 the next bar, etc. It's important to choose the value which represents the bar on which you want to act in your Signals and Modules.

Custom indicator page

Here you can upload, download or delete your custom indicators. You can also see which custom indicator is use by which expert advisor. If you would like to delete your custom indicator make sure it is not used by any of your expert advisors or else it cannot be deleted.

custom indicator page
Add, delete or download your custom indicators

Next: Signals