MQL5 TUTORIAL BASICS – 70 SIMPLE BWMFI OSCILLATOR

video
play-sharp-fill

In this video we are going to create an expert advisor for the Bill Williams Market Facilitation indicator, that’s the oscillator here, so let’s find out how to do that with mql5.
To get started 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 ea, click on continue, continue and finish.
Now you can delete everything above the ontick function and the two comment lines here.
We start with an include statement to include the file trade dot mqh because it contains the class ctrade and we create an instance called trade that we are going to use to open and close positions.
Inside of the ontick function, we start by creating a variable called signal. This is a string variable but we don’t assign a value so far because we are going to calculate that later.
First, we need to calculate the ask price that is done by using symbol info double for the current symbol on the chart, we use symbol underscore ask – all in capital letters – and with normalize double and underscore digits we calculate the number of digits behind the dot.
Let’s repeat that for the bid price, it’s almost the same except for the variable name and of course this time we are going to use symbol underscore bid.
Afterwards, we create an array for the Bill Williams Market Facilitation Index and now we use array set as series to sort the array from the current candle downwards.
So far so good! The bwmfi can be calculated with an included function. We need to pass a few parameters, the first one is for the current symbol on the chart, the second one is for the selected period on that chart and the third one is for the volume, we have two values that we can use, either volume tick for the tick volume or volume real for the real trade volume.
In our case, we will use the tick volume and now we use copy buffer to fill our according to the definition that we have created here. We do that for buffer zero starting from the current candle zero and we will fill the array with three candles and store the results in our array.
Now we can calculate the current value by looking into candle zero in our array. We use normalize double and the value five because the original oscillator also shows five digits behind the dot.
Now let’s repeat that for the value for candle one because that will make it possible for us to compare if we have a higher or a lower value and if the current bwmfi value is bigger than the last bwmfi value we consider that to be a buy signal so we assign buy to our signal.
Otherwise, if current bwmfi value is below the last value we consider that to be a sell signal so now we assign the word sell to our signal.
And if the signal equals sell and the function positions total delivers a return value from below one – that would mean that we have no open orders – and in that case, we use trade dot sell to sell ten micro lot.
Otherwise, if the signal equals buy and positions total is below one we would use trade dot buy and buy ten micro lot.
Finally, we create an output on the chart, we use the comment statement to output the text, the signal is now followed by the calculated signal.
Okay, so far so good!
If this was too fast for you or if you have no idea what all the code here does maybe you want to watch one of the other videos in the basic video series or maybe even the premium course on our website might be interesting for you, for now, please click on the compile button or press F7, 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 click on view, strategy tester or press control and r, please pick the new file, simple bwmfi ea dot ex5, mark the option for the visual mode here and start a test.
And here we see our first trade, the expert advisor is producing buy and sell signals.
Well, usually you would use an oscillator in combination with a trend indicator but in this little video you have learned how to create an expert advisor that is able to calculate buy and sell signals for the bwmfi oscillator and you