In this video we are going to trade this Indicator; it’s the Force Index Oscillator, I’m just now using the Robot Trading System and I would like to show you how to trade the Force Index for 10 years.
This is an entry module that I’m going to use in the Robot Trading System you could also use it in your own system, so let’s find out how to code this in MQL5!
To do that please click on the little button here or press F4 in your Metatrader, now you should see the Metaeditor, in my case I have loaded the Robot Trading System, you see I have all these entries here and this one is the one we are going to create right now.
To do that please click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this file: “CheckEntry_IForce”, click on “Continue”, “Continue” and “Finish”.
Now you should see something like this, here we can delete everything above the “OnTick” function and the two comment lines and to create this entry module (CheckEntry_IForce) we first need to create a string variable for the signal, that will also be called: “signal” but we don’t assign a value here.
The next thing we need to do is to create an array, we use “MqlRates” to create a price array (PriceArray) because “MqlRates” stores the information about price, volumes and spread. Afterwards we sort the price array (PriceArray) from the current candle downwards by using “ArraySetAsSeries” for our price array (PriceArray).
Now we fill the price array (PriceArray) with data for 3 candles by using “CopyRates” for the current symbol and the currently selected period on the chart. We start with the current candle 0 (zero), copy the prices for 3 candles and store it in the price array (PriceArray).
Now we need to create a second array, this one is for the Expert Advisor data (myPriceArray), let’s define the properties for the Force Index EA by using the built-in MQL5 function: “IForce”, this one also needs a few parameters: the first one is for the symbol, the second one is for the period, here we have 13 because if we click on: “Insert/ Indicators/ Oscillators/ Force Index”, you will see that it is calculated based on 13 candles, that’s what we use here. The last two parameters are: “MODE_SMA” and “VOLUME_TICK” because the calculation is done for a Simple Moving Average and we used the tick volume here. We also use “ArraySetAsSeries” for the second price array (myPriceArray) to sort it from the current candle downwards and with “CopyBuffer” we fill our price array (myPriceArray) with data according to the Force Index definition (ForceIndexDefinition) that we have created here. We do it for the first buffer – that’s buffer 0 (zero) – from the current candle 0 (zero) for 3 candles.
Let’s get the value for the current candle of the Expert Advisor, we will assign it to the value: “ForceIndexValue” and to get that value we just need to look at candle 0 (zero) in our price array (myPriceArray).
We use “NormalizeDouble” and a 6 because the Force Index has six digits behind the dot.
Now that we have calculated the value we just look if the Force Index value (ForceIndexValue) is below zero, in that case we would assign a “buy” signal to our signal variable, otherwise if the Force Index value (ForceIndexValue) is above zero we assign the word: “sell” to our signal.
In the last step we are going to return the signal to our main module, in my case it’s the Robot Trading System, it can trade all these entry modules here. If you don’t have a system you can go to: robottradingsystem.com or you could create your own version.
Now let’s compile the system. I’ve got a warning here that: “it’s not compatible with MQL5 market” but that’s not important for me and because we had no errors I can now click on the button here or press F4 to go back to Metatrader.
In Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, here we pick the main module, in my case it’s the Robot Trading System, let’s enable the visualization mode here and start a test.
…and here is our little Expert Advisor at work, it’s creating buy and sell signals here on the chart and for this video I’m going to do it in full speed to show you what kind of results you could expect for 10 years. So, let’s enable the graphic mode here and go to full speed.
…here we are! You can see the results down below, I will speed them up for you and now you know how to create an entry module for the Force Index Indicator and you have coded the entry yourself with a few lines of MQL5 code.
Download “MQL5 TUTORIAL - ADVANCED IFORCE ENTRY”AdvancedForceIndexRobot.txt – Downloaded 154 times – 1.15 KB