In this video we are going to create an entry module (CheckEntry) for this Indicator; this is the Commodity Channel Index Indicator, it’s an oscillator and it creates signals and whenever this green line here crosses one of the dotted lines it will create a signal. When the green line is above the upper dotted line that’s a sell signal because we expect the prices to fall, and when the green line is below the lower dotted line that would be a buy signal because now we expect the price to rise.
Now how can we create an Expert Advisor entry module (CheckEntry) for the Commodity Channel Index that is able to create buy and sell signals and actually trade with a main module like the Forex Trading Framework?
Well, to do that please click on the little button here or press F4 in your Metatrader and now you should see the Metaeditor window and here you want to click on “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this: file “CheckEntry_ICCI” click on “Continue”, “Continue” and “Finish” and now you can delete everything above the “OnTick” function and the two comment lines here and we don’t need a “void OnTick” function but we will make it a string function called: “CheckEntry”. Within that function we are going to create a string for the signal that will also have the name: “signal” but no value so far because we are going to calculate that now and that is done by using the “iCCI” function that comes with MQL4. It takes a few parameters; the first one is the symbol for the current chart, the second one and the last one our shift values. For example you could move the drawing of the Indicator to the right or to the left. We will calculate it based on 14 candles and we will use a typical price.
If you click on “Insert/ Indicators/ Oscillators/ Commodity Channel Index“ you will also see 14 candles and typical price and the default values here. Actually we want to buy if the value is above 100 – that is the case whenever this line here is crossed –, if we pause the Indicator here and click on “properties” you will see a tab called: “levels” the upper dotted line is on the plus 100 (+100) level and the lower one is on the minus 100 (-100) level so if the ICCI value (ICCIValue) is bigger than 100 we consider it to be overbought and so we assign the word: “sell” to our signal.
In the other case if it is below 100; so if ICCI value (ICCIValue) is smaller than minus 100 that would be a buy signal so we assign the word: “buy” to our signal and in the last step we need to return our signal to the main module.
So what’s the main module?
In my case it’s the Forex Trading Framework, this is basically a collection of functions to open and manage trades.
You can create and use your own main module or you could download the demo version of the Forex Trading Framework from my website, it uses the include statement to include the newly created file for the ICC here and basically you can trade almost every entry with it so when you are done with the entry module (CheckEntry) for the Commodity Channel Index just save the entry module (CheckEntry), import it in the main module, click on “Compile” and that worked without any errors here so now we can click on this little button or press F4 to go back to Metatrader.
In Metatrader we use a little trick, let’s click on “Insert/ Indicators/ Oscillators/ Commodity Channel Index“, we will go with the default values and click on “OK”, here is our indicator and now we right-click into the chart, click on “Template/ Save Template” and save it as: “tester.tpl” because this is the template that Metatrader is going to use for your back-test and if you don’t see the Strategy Tester here you click on “View/ Strategy Tester” or press CTRL and R, select your main module – in my case it’s the framework –, enable the option for the visual mode here and start your test.
Here is our little Expert Advisor at work it has already made a few trades and we have a little profit and now you know how to create an Expert Advisor entry module (CheckEntry) for the Commodity Channel Index Oscillator and you have coded it yourself with a few lines of MQL4 code.
Download “MQL5 TUTORIAL - ADVANCED ICCI EXPERT ADVISOR”AdvancedICCI.txt – Downloaded 1739 times – 451.00 B