MQL5 TUTORIAL – SIMPLE BWMFI EXPERT ADVISOR

video
play-sharp-fill

In this video we are having a look at the BWMFI Indicator, it’s the colorful indicator for the Market Facilitation Index by Bill Williams; BW is for Bill Williams and MFI is for the Market Facilitation Index.
The Market Facilitation Index can create bars and several colors. The MFI indicator is used to find correlations between the indicator and the volume, so if you want to know how to use it, just go to the Wikipedia webpage for the Market Facilitation Index. They also say as an indicator on its own the MFI is of no significant value, but it’s part of MQL5 and Metatrader5, so now we want to find out how we can create an Expert Advisor that is able to calculate the BWMFI value on our chart.
To do that, please click the little button here or press F4 on your keyboard and now you should see the Metaeditor window and here you want to select “File /New /Expert Advisor” from template (template), Continue (Next). I will call this one: “Simple BWMFI” (SimpleBWMFI). Now click on continue, continue and finish.
Now everything above the “OnTick” function can be deleted and we also want to remove the two comment lines here.
We start by creating an array for the Expert Advisor, we will call it: “BWMFIArray”, it’s a double array, so it can hold floating type values. Now we want to define the BWMFI Expert Advisor, and we used the MQL5 function: iBWMFI. That’s a built-in function, you can find it in the MQL5 reference, in the technical indicator section. It needs only three different parameters. The first one is for the symbol, the second one for the period, and the third parameter is for the applied volume.
Actually, when you click on “Insert /Indicators /Bill Williams /Market Facilitation Index” you will see that the standard value is the tick volume so we are going to use “_Symbol” for the currently selected currency pair on the chart, ”_Period” for the time period you have selected on your chart, and the third parameter is Volume_Tick because we want to use the standard default volume that comes with the Market Facilitation Index Indicator.
Okay.
Let’s go on and sort the array from the current candle downwards, this is done by using “ArraySetAsSeries” for the BWMFIArray we have created here.
For our defined EA we want to use the data for one buffer, that’s basically for the first indicator line. For example: for iBands – the Bollinger Bands – we would have three different buffers. The baseline would be buffer zero, the upper band would be buffer one and the lower band would be buffer two. We need to use the value from the current candle for at least 3 candles and store it in our array.
We use “CopyBuffer” for the BWMFI definition for buffer zero because this histogram here just needs one buffer and we copy the values from candle zero – that’s the current candle, candle zero is always the candle that is built on the right side here, this would be candle one, candle two, candle three, and so on – and we want to store the data in the BWMFI array (BWMFIArray) we just created. And now we can actually calculate the value for the current candle.
To do that we just have to have a look at the values for candle zero of the BWMFI array and we use “NormalizeDouble” and the five, because the indicator just needs to have five digits behind the dot.
Finally, we create a chart output, this is done by using the “comment” function, it will output the word: “BWMFIValue” followed by the actual value that we have calculated here.
Okay. That’s it. Let’s click on the compile button or press F7, and now you should see zero errors and zero warnings and in that case, you can click on the 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, and here you want to select the SimpleBWMFI.ex5 file.
Mark the visualization option here and click on start. And now you should see something like this on your chart, you can see colorful bars here, next here is the calculated value and as I said I’m not the biggest fan of this indicator but maybe you want to try it out and now you have coded it with a few lines of MQL5 code.

Download “MQL5 Tutorial - Simple BWMFI Expert Advisor” SimpleBWMFI.txt – Downloaded 308 times – 697.00 B