In this video we want to code a standalone version for the trading of the Bulls Power Indicator this Expert Advisor is going to output buy and sell signals directly on the chart and it’s also possible to open positions with it, everything is done automatically and now let’s find out how to do that with MQL5!
To do that please click on the little button here or press F4 in your Metatrader, 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 one: “SimpleBullsPowerStandaloneEA”, click on “Continue”, “Continue” and “Finish”, now we can delete everything above the ”OnTick” function and let’s also remove the two comment lines here.
We start by including the file: “Trade.mqh” that one comes with MQL5 and now we are able to create an instance of the class: “CTrade”, that instance will be called: “trade” and we are going to use it to open new positions later on.
First we need to calculate a few things, we start by calculating the Ask price and the Bid price that is done by using “SymbolInfoDouble” for the current symbol and we either use “SYMBOL_ASK” or “SYMBOL_BID” to calculate the prices, we also use “NormalizeDouble” and “_Digits” to automatically calculate the right number of digits behind the dot because some currency pairs only have 3 digits and other ones have 5 digits behind the dot.
Now let’s create a string for the signal that will be called: “signal” and we don’t assign a value here because that is going to be calculated later on. First we use “MqlRates” to create an array for the prices that will be called: “PriceInformation”. “MqlRates” is a structure that stores the information about prices, volumes and spread. With “ArraySetAsSeries” we sort the array (PriceInformation) from the current candle downwards and by using “CopyRates” we copy the price data into the array (PriceInformation), we do it for the current symbol and the currently selected period on the chart, we will start with the current candle 0 (zero), copy the price data for 3 candles and store it in the price information array (PriceInformation).
Now let’s create a second array (myPriceArray), this one will be the array for the Expert Advisor data, it is also going to be sorted downwards by using “ArraySetAsSeries”.
Now we use the integrated “iBullsPower” function of MQL5 to define the bulls power EA (BullsPowerDefinition) for the current symbol and the currently selected period. The third parameter is 13 and if you click on: “Insert/ Indicators/ Oscillators/ Bulls Power” you will see that it is calculated based on the last 13 candles so that’s what we use here.
Now we use “CopyBuffer” to fill the array (myPriceArray) with data according to the Bulls power definition (BullsPowerDefinition) that we have created here we do that for the first buffer – that’s buffer 0 (zero) – from the current candle 0 (zero) for 3 candles and we store the information in our price array (myPriceArray)
Now let’s calculate the current value that is done by looking at candle 0 (zero) in our price array (myPriceArray) and we assign the value to the floating type variable Bulls power value (BullsPowerValue) and if the “BullsPowerValue” is above 0 (zero) we consider that to be a buy signal so we assign the word: “buy” to our signal. In the other case if the “BullsPowerValue” is below 0 (zero) we consider that to be a sell signal so we assign the word: “sell” to our signal and if the signal equals sell and “PositionsTotal” is below 1 – that will mean that we have no open positions – we use “trade.Sell” to sell 10 micro lot. In the other case if the signal equals buy and we also have no open position we use “trade.Buy” to buy 10 micro lot.
Finally we want to create a chart output by using the “Comment” function, this one will output the words: “The current signal is:” followed by the signal.
That’s it so far, please click on the “Compile” button or press F7 and if that works without any errors we can click on the little button here or press F4 to go back to Metatrader.
In Metatrader we click on: “View/ Strategy Tester” or press CTRL and R here we pick the file: “SimpleBullsPowerStandaloneEA.ex5”, please enable the visualization here and start a test.
And this is our little Expert Advisor at work, we have buy and sell signals directly on the chart, this is our first position that has been opened totally automated and in this little video you have learned how to create a very simple Expert Advisor standalone version for the Bulls Power Indicator and you have coded it yourself with a few lines of MQL code.


SimpleBullsPowerStandaloneEA.txt – Downloaded 2161 times – 1.71 KB