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
Moving average indicator

We've added a couple of predefined variables, which are technically not indicators, but these can still be found at the indicator part of our platform: Ask, Bid, 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 indicators.

Indicators
Duration: 17 minutes

There are 2 ways to upload a custom indicator:

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

Add a new Indicator

upload custom indicator
Here you can add your custom indicators

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

So you've uploaded your custom indicator. You've probably experimented with it in MetaTrader, or you've been working with it already. This means that we don't have to tell you which input values you have to use, and which ones are optional. However, ther are 2 exceptions that need discussion: the Mode and Shift parameters.

Mode

If your custom indicator has more than one possible output value, it is important to retrieve the one you want to use in your auto-trader. To find the correct Mode input value, you can investigate at which event or output you want to take action. There are basically 4 options:

  • You're waiting for an object, like an arrow or the value of a line drawn
  • 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 variable values. It's important to know a comprehensive indicator exists of multiple collections of arrows or lines: f.e. the up-arrows and the down-arrows. Both are maintained in their own value-set, called 'buffers'. What you need to do is select the correct buffer for your trading strategy and enter it in the 'Mode' input. If you don't know this value in advance, you can use the following strategy to get the right Mode value: First, load your indicator in Metatrader. Let's f.e. assume you have this indicator:

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

Note that my mouse pointer is at the up arrow in the image above. 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 exposing and which can be used by your EA. The rows have 2 columns. The first column shows the values the indicator gives me at 20:15, one bar before the bar I've selected. The second column shows the values the indicator gives me at 20:30. One of the two rows displays a value. It's the value of the position the up arrow is at.

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

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

In order to automate this indicator, 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 output 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 outputs 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.

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 input 1 was chosen. 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 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 we're comparing the current bar and the previous bar with value '2147483647'. This value represents 'empty_value'. The logic is correct and works because of 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 empty and the value of the current bar is unequal (!=) to empty. The value representing 'empty' is '2147483647'.

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

Colour switch

As you know indicators can sometimes show a line which changes colour from red to blue (or green) and vice versa. You probably use these in your manual (visual) trading. Now that you want to automate your strategy you want to select 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 select the correct buffer for your trading strategy and enter it in the 'Mode' input. To get the correct value, you need to load your indicator in Metatrader. Let's assume you have this indicator:

custom indicator with colour
Image 5. An colour indicator. (1) Position/ tme 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. 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 close to (2)). These are the 'buffers' that the indicator is exposing and which can be used by your EA. The rows have 2 columns. The second column shows the values the indicator gives me 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 will see the first value is filled and the second value is empty.

This is 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 'a' value. It's irrelevant which value the buffer gets, which you will understand in a minute.

In order to automate this indicator, 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 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 we're comparing the current bar and the previous bar with value '2147483647'. This value represents 'empty_value'. The logic is correct and logical because of 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 and the value of the current bar is unequal (!=) to empty. The value representing 'empty' is '2147483647'.

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 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 &
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 check for a cross-over to occur. Creating an 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 else it cannot be deleted.

custom indicator page
Here you can add, delete or download your custom indicators

Next: Signals