MQL4 TUTORIAL BASICS – 70 SIMPLE BWMFI OSCILLATOR

video

In this video we are going to calculate the Bill Williams Market Facilitation Index, that’s the oscillator here, so let’s find out how to do that with mql4.
To start please click on a little icon here or press F4 on your keyboard, now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file, simple bwmfi ea, click on continue, continue and finish.
Now you can delete everything above the ontick function and the two comment lines here.
We start by creating a string variable for the signal but we don’t assign any values here.
Afterwards, we use the included ibwmfi function that comes with mql4, we need to pass three parameters. The first one is for the current symbol on the chart, the second one is for the currently selected time frame on that chart and the last one is a shift value. If we mark the function and press F1 we learn that the shift value means that it is relative, so zero means that we are calculating the current bar, now let’s repeat that to calculate the last bwmfi value for candle one. Except for the variable name and the last parameter, everything else is the same.
And now we can compare the values and if the current bwmfi value is bigger than the last value we would consider that to be a buy signal and that’s where we assign the word buy to our signal.
Otherwise, if the current value is below the last value we would consider that to be a sell signal and then we would assign the word sell to our signal.
And if our signal equals buy and the function orders total has a return value of zero – that would mean that we have no open orders and we have a buy signal – and that’s when we use order send to buy ten micro lot.
Otherwise, if the signal equals sell and orders total is zero – that would mean that we have a sell signal and no open orders – and now we use order send to sell ten micro lot.
Finally, we want to create an output on the chart, so we use the comment statement to output the text, the current signal is, followed by the calculated signal and that’s all.
Well, if you don’t understand what all the code here does or if this was too fast for you maybe you want to watch the other videos in the basic video series first or maybe even the premium course on our website might be interesting for you, for now, please click on the compile button here or press F7 on your keyboard. You shouldn’t get any errors and if that is the case you can click on the little button here or press F4 to go back to Metatrader.
And in Metatrader we want to open a clean chart, now please click on insert, indicators, Bill Williams and select the Market Facilitation Index, we will go with the default values and click on okay.
Now you should see the oscillator in the chart below, please right-click into the chart, select template, save template and save it as tester dot tpl because this is the template that is going to be used in the strategy tester. You can overwrite the current value and if you don’t see the strategy tester below you want to click on view, strategy tester or press control and r.
Please pick the new file, simple bwmfi ea dot ex4, enable the visual mode here and start a test.
Here we are! The expert advisor is running, it’s creating buy and sell signals and we see that we have produced the first sell trade here. Usually, you would use an oscillator in combination with a trend indicator but in this little video you have learned how to calculate the Market Facilitation Index and you have coded it yourself with a few lines of mql4 code.