Forex Trading Framework – IVIDYA Entry Module

In this video today we are going to learn about the Variable Index Dynamic Average Indicator and how to code an automated system with it. The red line here is the Variable Index Dynamic Average Indicator.
Let’s use the function “iVIDyA” to code the EA which shall trade based on its signals. The VIDYA takes several parameters; we go through them one by one.
For our Expert Advisor to do that it must return the handle of the Variable Index Dynamic Average Indicator, so let’s start coding it.
First of all let’s check out the indicator settings!
Please click on “Insert /Indicators /Trend /Variable Index Dynamic Average”, here you will see that it has a CMO period of 9 and an EMA period of 12. We will use these values later on. If you place your mouse above the Indicator here or click properties then this is another way to access the Indicator’s settings and you will see the same values. We have a shift value here which is zero and we apply the price value calculation to the close price.
Alright. Its time to begin the code, please start up the Metaeditor window by clicking on the little button here or use the F4 short key on your keyboard. If your Metaeditor is running please click on “File /New /Expert Advisor” from template (template), Continue (Next). Let’s name the new Expert Advisor as: “CheckEntry_ IVIDYA” then we click on continue, continue and finish.
As usual please remove everything above the “OnTick” function plus the two comment lines and this time delete the “OnTick” function as well because we need another one which is: “CHECK_ENTRY”. In the first line here create a variable and we call it signal. This is a string- variable which has no any value yet for we are going to calculate it later.
Next we code an array for the price data, we use “MqlRates” to do that then we sort the data in our array from the current candle downwards. “ArraySetAsSeries” will do that for us for the “PriceArray” we have defined here. We want to fill the “PriceArray” with values for 3 candles only. This is done by “CopyRates” here for the current symbol and the currently selected period on the chart. The calculation begins with candle 0, and then we copy the values for 3 candles only and store these values in the “PriceArray”. For the Expert Advisor we need another array, so we use “ArraySetAsSeries” the second time here for rendering the data in the Expert Advisor array (EAArray) in the necessary order from the current candle downwards. Once we have all the price values calculated we can define the actual Expert Advisor. The “iVIDyA” function is the one we need; it will use the current symbol which is sat on the chart and the current period which is also sat on the chart. We set a 9 and a 12 here. These values should look familiar for they are the same values which we have seen before when we checked on properties of the VIDYA Indicator. So, these are the CMO period and the EMA period here. The zero is for the shift value and for our price value calculation we want to use “PRICE_CLOSE” because we need data for the close prices which the Expert Advisor will process.
For better understanding you can look up more information about the “iVIDyA” function by launching the “Help” function from the Metaeditor window or by pressing F1 on your keyboard. Here you can see the description of any MQL5 function.
So, next we use “CopyBuffer” and the Expert Adviser definition for copying the calculated price data we need into buffer 0 from the current candle 0 for 3 candles and we store it in “EAArray”.
We can do now the final calculations for the actual signals. So we get the current value by getting candle 0 only from our Expert Advisor array we have coded above and we create our signal based on it. If the value we get is above the close price for candle 1 in the “PriceArray” then it is a buy signal therefore we assign the word “buy” and if we get a value which is below the close price for candle 1 in the “PriceArray” then it is a sell signal and we assign the word: “sell”.
Our final step in the code is to return the signal to our main module by using the “Return” function. I’m using my Forex Trading Framework I have coded before, this is my main module. What is a framework? It is a module which contains several predefined functions so I can use it with any entry module I like and it can manage trades based on any criteria I like.
Now we only left with the compilation of the code then running a test in the Strategy Tester. Once you are done compiling the code please click to go back to Metatrader. In Metatrader let’s click on “View /Strategy Tester” or press CTRL + R. If the “Strategy Tester” window is running, please select the Forex Trading Framework; select also a currency pair, or your own main module. For the visualization mark the checkbox and start your test. Let’s also enable the graphical overlay and turn it up to full speed.
Alright. You just learned how to program the IVIDYA Expert Advisor entry by using a few lines of MQL5 code only.

Download “Forex Trading Framework - Advanced IVIDYA Entry Module” AdvancedIVIDYA.txt – Downloaded 18 times – 1 KB