With MQL5 and Metatrader5 we can use the iBearsPower function to create an Expert Advisor for the Bears Power Indicator that is included in Metatrader. Use it in your trading robot to find out, if the bulls or the bears are stronger…
This time we are talking about an Expert Advisor created for the Bear’s power oscillator.
You might know that Bulls and Bears are always fighting every day and with this oscillator you can see how strong the Bears actually are.
The largest value on the whole day actually happened here, right before the price went through the roof.
This oscillator was created by Alexander Elder. And he believes that the lowest price displays the maximum seller’s power within a day.
You might know his book- Trading for a living. I think that is an interesting read and in this case he’s right.
Now how can we create an Expert Advisor for this oscillator in MQL 5?
First please click on this little button here or press the F4 key to bring up the Meta-Editor, and in the MetaEditor click on File, New, Export Advisor from template, continue, we will give it the name simple Bear’s power.
Now click on continue, continue, finish and remove everything above the Ontick function, and the two comment line here can also be removed.
And we will start by creating a price array. This is a double array called my price array and now we are going to define the properties of the Bear’s power EA by using the function iBears power for the current symbol and the selected period on your chart .
That might be a one minute or hourly chart for example and we want to calculate our value based on the last thirteen candles, because this is what Mr Elder recommended.
You might also use the indicator together with a trend indicator like a moving average.
But back to topic, after we have defined our iBears power indicator we want to sort the price array from the current candle downwards by using the arraysetasseries function for our defined price array and now we use copybuffer and the Bear’s power definition we have created here to calculate one line or, in our case one value, that’s what the zero stands for.
For the current candle that’s candle zero; for three candles and store it in my price array, the array that we have created here.
And now we actually want to calculate the Bear’s power value.
We grab the value of candle zero in my price array and now we want to output the text Bear’s power value and the calculated value on our chart by using the comment function. And that’s it.
Let’s compile the Expert Advisor by clicking this little button or pressing the F7 key and you should see no errors and no warnings.
So now we can click this little button here or press the F4 key to go back to Metatrader. In Meta Trader please click on View, Strategy Tester or hit the Control and the R key, and that will bring up the little Strategy Tester Panel here.
And there you want to select the SimpleBearspower.ex5 file. Please mark the visualisation option here and click on start.
And this is what you should see on your chart. The calculated value here is a little bit longer than the indicator output. Now I would change this double value to a float type and compile the Expert Advisor again.
And now it says we could have a possible loss of data and this is true we have lost one digit, but it will now also only consume four bytes instead of eight bytes of memory.
Okay, now you know how to create an Expert Advisor for the Bear’s power indicator and you have done it with a few lines of MQL 5 code.