In this video we are going to have a look at this indicator; it’s called: Ichimoku Kinko Hyo, it produces a lot of indicator signals here on the chart and there are several different interpretations how to use this Indicator.
In our example we are going to calculate the value of the red line here, it has a value of: 0.811800 and that’s exactly what we have calculated here, so let’s see how we can do that in MQL5!
To do that please click on the little button here or press F4 on your keyboard, 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: “SimpleIchimoku” click on “Continue”, “Continue” and “Finish” and now we can delete everything above the “OnTick” function and the two comment lines here.
Okay, first we need to create an array for the price data, this one will be called: “TenkansenArray” because the red line you see here is the Tenkan-sen line and we use the function: “iIchimoku” that comes with MQL5 for the current symbol on the chart and the currently selected period. These 3 values here can also be found when you click on: “Insert/ Indicators/ Trend/ Ichimoku Kinko Hyo” and here we see that the Tekan-sen has a value of: 9, the Kijun-sen has a value of: 26 and the Senkou Span B has a value of: 52; that’s what we use here 9, 26, 52.
Okay, let’s use the “ArraySetAsSeries” command to sort the prices from the current candle downwards for our Tenkan-sen array (TenkansenArray) and with “CopyBuffer” we fill our Tenkan-sen array (TenkansenArray) according to the Ichimoku definition (IchimokuDefinition) we have created here for one line. The first line is for buffer 0 (zero) from the current candle 0 (zero) for 3 candles – that’s the 3 here – and store the result in our Tenkan-sen array (TenkansenArray).
To calculate the value for the current candle we simply look at the candle 0 (zero) – that’s the current candle in our Tenkan-sen array (TenkansenArray) – and we assign the result to the Ichimoku value (IchimokuValue) variable here.
Finally we need to create a chart output that is done by using the “Comment” function, it will output the word: “IchimokuValue:” followed by the calculated value directly on our chart.
When you are done you can click on the “Compile” button or press F7; that worked without any errors here so now we can click here or press F4 to go back to Metatrader.
In Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, here you want to select the “SimpleIchimoku.ex5” file, mark the visualization option and click on start.
…and here we are, we can stop the Expert Advisor at any time and when you point your mouse above the red line you should see a Tenkan-sen value; this one is: 0.8128, that’s exactly what we have calculated here with MQL5.
Well, if you would like to calculate one of the other signal lines here you just would have to use another buffer line, you see 0 (zero) stands for the Tenkan-sen line, the 1 (one) would be the Kijun-sen line, let’s stop the Expert Advisor here and when you point to the blue line you should see that it is called: Kijun-sen, that’s what we want to calculate, so let’s exchange buffer 0 (zero) with buffer 1 here, recompile the code and start another test.
Now we get other values here, this one is: 0.813225, it’s not the Tenkan-sen line anymore but now it’s the result for the Kijun-sen line.
Okay. In this little video you have seen how to calculate values for the Ichimoku Kinko Hyo Indicator and you have coded it yourself with a few lines of MQL5 code.
Download “MQL5 TUTORIAL - SIMPLE ICHIMOKU Kinko Hiyo”SimpleIchimoku.txt – Downloaded 378 times – 700 B