

Let’s try it again, and this time it worked without any errors and no warnings so now we can click the little button here or press F4 to go back to Metatrader.Īnd in Metatrader you want to click on “View, Strategy Tester” or press CTRL and R on your keyboard. Please don’t forget the last bracket and when you’re done you can click on the Compile button here – oh I messed up this character here! So, let’s create a chart output that’s about it. In the other case if “myMovingAverageValue” is below the close price for candle 1 – that would be a buy signal. In that case we have a sell signal, so we use the “Comment” function to create a chart output for the sell signal. Now that we have done that, we check if “myMovingAverageValue” is above the close price of candle one in our “PriceInformation” array. To calculate the Expert Advisor for the last candle we select candle one from “myMovingAverageArray” and store the result in “myMovingAverageValue”. You could use more but calculating three candles is much faster and the values will be stored in “myMovingAverageArray”. We only need the values for three candles. We start from candle zero, that’s the current candle. Let’s also sort this array by using “ArraySetAsSeries” to sort the price array from the current candle downwards and once again we use “CopyBuffer” for the “movingAverageDefinition” we have created here for buffer zero, because the Expert Advisor only has one signal line. Let’s exchange this one to a zero, because we don’t want to use any shift value here and the Expert Advisor should be calculated based on the close prices. The result will be stored in an integer variable called: “movingAverageDefinition” and we use the function iDEMA for the current symbol and the currently selected period on the chart for 14 candles. This one is for the Moving Average and now we use the iDEMA function of MQL5 to define the properties for the Double Exponential Moving Average. We only need prices for three candles and those candles go into our “PriceInformation” array. We will start with the current candle, that’s candle zero. That is done by using the “ArraySetAsSeries” and now we use “CopyRates” to fill the array with price data for the current symbol and the period that is currently selected on the chart. We will call it: “PriceInformation” and we use MqlRates to create it.Īfter that we are going to sort it from the current candle to the oldest candle. Now everything above the “OnTick” function can be deleted and please also delete the two comment lines here. (Simple Double Exponential Moving Average) Click on continue, continue and finish. I will call this one: SimpleDoubleExponentialMovingAverage. Here you want to click on “File, New, Expert Advisor (template)” from template. To do that please click on the little button here or press F4 in your Metatrader and now you should see the Metaeditor window. Now how can we create an Expert Advisor that is able to calculate the indicator? You see that it is going to generate buy or sell signals on our chart and basically a buy signal will always occur when the Double Exponential Moving Average is below the close prices of our candles and when it’s above our close prices here we will generate a sell signal. The shift will be zero because we don’t want to move it to the right or to the left.įor the applied price, we will use the close price. The function only has one buffer, it takes the current symbol, the current period on the chart, the third parameter will hold a period. The Double Exponential Moving Average can be called by using the MQL5 function: iDEMA. The standard value is 14 candles, it has no shift and it applies to the close price. You can find the indicator if you click on: “Insert, Indicators, Trend, Double Exponential Moving Average”. If you hover the mouse over the line you will see that the Double Exponential Moving Average (DEMA) has a value. In this video, we are going to trade the Double Exponential Moving Average (DEMA) that’s basically a red line you see on your chart.
MQL5 EMA MOVING AVERAGE ARROWS CODE
Copy and paste this HTML code into your webpage to embed.
