MQL5 TUTORIAL – Advanced ICCI Expert Advisor

In this video we are going to talk about the ICCI Indicator, it’s an oscillator that calculates the Commodity Channel Index.
The Commodity Channel Index is an oscillator, you see that the signal line is changing between values on the upper and on the lower side and whenever the signal line is above the upper dotted line that will create a sell signal and when it’s below the lower dotted line we have a buy signal.
In this video we are going to create an entry module that is going to produce entry signals for the Forex Trading Framework and to do that please click on a little button here or press F4 on your keyboard and here we want to click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this version: “CheckEntry_ICCI” because this is what we are going to call from the Forex Trading Framework.
Now let’s click on “Continue”, “Continue” and “Finish” and now you can delete everything above the “OnTick” function and the two comment lines here.
For the advanced version we are going to exchange “void OnTick” with “string CheckEntry”, first we create a string variable that will contain our signal; it’s also being called: “signal” and we don’t assign a value here.
Let’s create an array for the price data that will be called: ”myPriceArray”, it’s a double array so it can contain floating type values. Now we define the ICCI by using the built in function: “iCCI”, it uses the current symbol on the chart as the first parameter, the second parameter is for the period on the chart – that might be 1 minute or 30 minutes or anything else – we will calculate the result for 14 candles and we use “PRICE_TYPICAL”.
Let’s click on: “Insert/ Indicators/ Oscillators/ Commodity Channel Index” and here you will see the 14 candles and that we use the typical price and the default values so let’s click on: “OK” and that’s what we are going to use here.
We sort the data from the current candle downwards by using “ArraySetAsSeries” for our price array (myPriceArray) that we have created here.
Now we use “CopyBuffer” for our ICCI definition (ICCIDefinition), this 0 (zero) is used for the signal line, the second 0 (zero) is for the current candle, we are going to copy the values for 3 candles and the result will be saved in our price array (myPriceArray).
Now that we have done that we can calculate the ICCI value (ICCIValue) by looking at candle 0 (zero) in our array (myPriceArray). A sell signal would be if the ICCI value (ICCIValue) is above 100 – that’s the dotted line here – and in that case we assign the word: “sell” to our signal. In the other case if the ICCI value (ICCIValue) is below the -100 mark – that’s the lower dotted line here – we expect the price to rise so we assign the word: “buy” to our signal.
Let’s remove the capital S here, so that’s basically it.
We don’t need to compile the module just save it. This is my main module, I’m using the Forex Trading Demo Framework here, it contains a collection of functions for different tasks, basically those functions do the trade management and now we use the include statement to import our newly created “CheckEntry_ICCI” module and call the function: “CheckEntry” that we have created here and it will return either buy or sell and to do that we use the “return” statement and it returns our ICCI signal, so let’s save that again, go into your main module (I have to recompile the Forex Trading Framework here, you could also use your own main module or download the demo version from our website).
This worked without any errors and I have only one warning so now I can click on a little button here or press F4 to go back to Metatrader and in Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, now we have the Strategy Tester here, I select the main module: “Forex Trading Framework”, let’s enable the visualization mode here and start a test.
…and here we are, it’s already trading and we already made a little profit here and now you know how you can code an entry module (CheckEntry) using the Commodity Channel Index and you have coded it yourself with a few lines of MQL5 code.

Download “MQL5 TUTORIAL - ADVANCED ICCI EXPERT ADVISOR” AdvancedICCI.txt – Downloaded 12 times – 966 B