This time we are talking about the ITEMA Indicator. This is for the Triple Exponential Moving Average Indicator. You see this red line here. If we pass the strategy test and hover over the red line you will see that it is called the Triple Exponential Moving Average and its calculated based on 14 candles.
In this video we are going to find out how to create an Expert Advisor to calculate a Triple Exponential Moving Average Indicator and how to improve the frequency of the signals that are created.
To do that please click the little button here in your Metatrader or press F4 on your keyboard and now you should see the Metaeditor window and here you want to click on “File -New -Expert Advisor” from template (template), Continue (Next). I will call this one: “Simple ITEMA” (SimpleITEMA). Click on continue, continue and finish.
Now everything above the “OnTick” function can be removed, let’s also delete the two comment lines.
First we need to create an array for the prices, that’s done by using “MqlRates” and the array will be called: “PriceArray”. We use the MQL5 built-in function “ArraySetAsSeries” to sort the price array from the current candle downwards and with “CopyRates” we fill the array for 3 candles. That’s enough to calculate the current candle and calculate crossovers. “CopyRates” takes a few parameters, first one is the symbol parameter – that’s for the current currency pair on the chart – the second one is for the currently selected period on the chart. We start with candle zero; that’s the current candle, copy the data for 3 candles and store it in the price array.
In the next step we to create another array for the Expert Advisor data, that will be called “EAArray” and the Expert Advisor array also need to be sorted by using “ArraySetAsSeries”.
Now it’s time to actually define the ITEMA Expert Advisor. That is done by using the built-in function: “iTEMA”, it takes a few parameters: the first one once again is the currency pair on the chart, the second one is once again the selected period on the chart, these are 14 candles because if you click on “Insert -Indicators -Trend -Triple Exponential Moving Average” you will see that the default value for the built-in indicator also is 14 candles. We use a shift value of 0 here and it applies to the close price, so that’s what we are using here: shift value 0 and “PRICE_CLOSE “. Now that we have created the definition we use “CopyBuffer” for the ITEMA definition (iTEMADefinition) we have created here. The 0 is for the first buffer, this 0 stands for the current candle, the 3 is to copy 3 candles and we want to save it in the array called: “EAArray”. Now that we have done that we calculate the ITEMA value (ITEMAVALUE) for the current candle 0 in our array. I use float, usually it’s a double and if you press F1 you will see that a double variable is 8 bytes in size, a float variable only takes half of the size and it’s better to read for us humans. So, let’s create a chart output depending on the direction. If the ITEMA value is bigger than the close price of the first candle in the price array – remember the first candle is always this one, this is candle zero, candle one, candle two and so on – so, if this expression is true we use the “Comment” function to output the text: “iTEMA IS SHORT”, followed by the calculated ITEMA value. In the other case if the close price for candle one in our price array is above the ITEMA value we will output: “iTEMA IS LONG”, also followed by the value.
Okay, that’s it.
When you are done you can click on the compile button here, we get a warning that says that we have a possible loss of data due to type conversion, that’s because I used a float variable here but for this little Expert Advisor that is okay. So, if the compilation works without any errors you can click the little button here or press F4 to go back to Metatrader.
In Metatrader please click on “View -Strategy Tester” or press CTRL and R and now you should select the file: SimpleITEMA.ex5, mark the visualization option here and start a test.
This is how our Expert Advisor looks like, you see it saying: “iTEMA IS SHORT “or “iTEMA IS LONG”.
The frequency of the signals is much too high, so let’s fix that!
We go back into the Metaeditor and change the shift value for the candles to 100 candles. Let’s recompile the code, press F4, stop the current test and start a new one!
This is how it looks like, just press the minus key a few times and now you see that the indicator is calculated 100 candles before the price and whenever the price is crossing here we will get another signal. Let’s speed that up a little bit, now we are getting much fewer signals but the signal quality is better!
Okay. That’s it!
Now you know how to create an Expert Advisor for a Simple Triple Exponential Moving Average Indicator and you have coded it yourself with a few lines of MQL5 code.

Download “MQL5 Tutorial - Simple ITEMA Expert Advisor” SimpleiTEMA.txt – Downloaded 10 times – 1 KB

Learn how to create your own MQL5 trading robot for FREE!
Sign Up Now