This time we want to trade the Relative Vigor Index that’s the Indicator here.
On the chart you can see that it is going to create buy or sell signals depending on the value of these two lines here. If both lines are above the dotted line that would be a sell signal and when both lines are below the dotted line that would be considered to be a buy signal.
Now how can we create an Expert Advisor that is able to trade the relative vigor index in full speed?
To do that, please click the little button here or press F4 on your keyboard and now you should see the Metaeditor window. I’m going to use the Forex Trading Framework from October 2017 and the new entry module will be called: CheckEntry_RVI. So let’s copy that, click on “File /New /Expert Advisor” from template (template), Continue (Next). I need to include the past to the Forex Trading Framework here, paste the name for the new entry module, click on continue, continue and finish.
Now everything above the “OnTick” function and the two comment lines here can be removed.
First we need to create a string for the signal that will also be called signal and we don’t assign a value here because that needs to be calculated.
In this case I need two arrays because the Indicator uses two different lines here and you see the two lines also have different values. Let’s define the properties for the Expert Advisor, this time we are using the “iRVI” function and we need to pass the current symbol on the chart, the selected period on the chart and the third parameter is a 10. When you have a look at the Indicator itself you will also find the 10 here, let’s right-click on the properties and we see that the ten is the period for the calculation.
Now we use “ArraySetAsSeries” for both of our arrays to sort the arrays from the current candle downwards and with “CopyBuffer” we use the RVI definition (RVIDefinition) we have created here to fill buffer 0 and buffer 1 from the current candle 0 for 3 candles and store the values in price array 0 (myPriceArray0) and price array 1 (myPriceArray1) and now we can calculate the current value for line 0 and line 1 all we need to do is to get the value for candle 0 from my price array 0 (myPriceArray0) or my price array 1 (myPriceArray1) and store the results in the variable called: “RVIValue0” or “RVIValue1” and with “NormalizedDouble” and a 3 we make sure that we get 3 digits behind the dot, that’s also what you see when you hover with the mouse over one of the two lines here.
Now let’s create a buy signal. If “RVIValue0” is below “RVIValue1” and if both RVI values are below zero – that would be the case when both of the lines are below the dotted line here – we would consider that to be a buy signal so we assign the word “buy” to the signal. In the other case if “RVIValue0” is greater than “RVIValue1” and if both RVI values are above 0 – so now both lines need to be above the dotted line here – we would assign the world “sell” to our signal. Finally we return the signal to our main module by using the “return” function in my case I use the Forex Trading Framework from October 2017 as a main module. Basically a framework is a collection of functions that are able to open and handle trades, for example this function here would set the position size, you could also code your own framework or get the demo version on forextradingframework.com and because I am going to call the “CheckEntry” function down below here I need to rename our function here to “CheckEntry” and it’s a string type function because we are going to set and return a string.
Now let’s save the file here, I need to recompile my framework, that worked without any errors so now I can click on the little button here or press F4 to go back to Metatrader.
In Metatrader you want to click on “View/Strategy Tester” or press CTRL and R on your keyboard and in the “Strategy Tester” panel I select the Forex Trading Framework from October 2017.
Let’s enable the visualization mode here and start the test.
Now our framework is trading, we are already cashflow positive and in this short video you have learned how to create an entry module for the Relative Vigor Index and you have coded it yourself with a few lines of MQL5 code.
Download “MQL5 Tutorial - Advanced RVI Expert Advisor”AdvancedRVI.txt – Downloaded 288 times – 1 KB