MQL5 TUTORIAL – SIMPLE BEARS POWER STANDALONE EXPERT ADVISOR

video
play-sharp-fill

 

Introduction to Standalone Bears Power Expert Advisor (00:00 – 00:15)

  • Introduction to creating an Expert Advisor for the Bears Power Indicator in MQL5, aiming to produce signals visible on the chart for automated trading.

Opening MetaEditor for MQL5 Programming (00:15 – 00:44)

  • Instructions on opening MetaEditor in MetaTrader and creating a new Expert Advisor file named ‘SimpleBearsPowerStandaloneEA’. Initial setup and code preparation.

Including Trade.mqh and Initializing Variables (00:44 – 01:17)

  • Steps to include the ‘Trade.mqh’ file and create an instance of the ‘CTrade’ class for opening positions later in the code.

Calculating Ask and Bid Prices (01:17 – 01:55)

  • Explanation of calculating Ask and Bid prices using ‘SymbolInfoDouble’ and normalizing these prices with ‘NormalizeDouble’ and ‘_Digits’.

Setting Up Price and EA Data Arrays (01:55 – 02:25)

  • Creating and sorting a price array (PriceInformation) using ‘MqlRates’ and ‘ArraySetAsSeries’. Also, setting up an array for the Expert Advisor data (myPriceArray) and sorting it.

Implementing Bears Power Indicator (02:25 – 03:11)

  • Using the ‘iBearsPower’ function to define the Expert Advisor based on the Bears Power Indicator. Filling the myPriceArray with data using ‘CopyBuffer’.

Calculating and Assigning Signals (03:11 – 04:12)

  • Determining the current Bears Power value and assigning ‘sell’ or ‘buy’ signals based on its value being below or above 0, respectively.

Executing Trades Based on Signals (04:12 – 04:41)

  • Executing sell or buy trades using ‘trade.Sell’ or ‘trade.Buy’ based on the calculated signal and the absence of open positions.

Displaying Signal on Chart and Testing (04:41 – 05:21)

  • Using the ‘Comment’ function to display the current signal on the chart. Instructions for compiling the code and testing the Expert Advisor in MetaTrader.

Conclusion and Strategy Testing (05:21 – 05:33)

  • Conclusion of the tutorial with a demonstration of the Expert Advisor in action, showing buy and sell signals, and an explanation of how the Bears Power Oscillator is typically used to filter another entry signal.

 

In this video we are going to talk about this Indicator, it’s the Bears Power Indicator and we want to create an Expert Advisor that is able to actually produce signals that will be seen right here on the chart and in this case we use the Bears Power Indicator tool trade automated.
Usually this Indicator is used as a filter and you would use another signal and only when the signal and the filter are pointing in the right direction you would open a new position.
To code that please click on the little button here or press F4 on your keyboard, now you should see the Metaeditor window and here we want to click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this one: “SimpleBearsPowerStandaloneEA”, click on “Continue”, “Continue” and “Finish”, now you can delete everything above the “OnTick” function and the two comment lines here.
We start by including the file: “Trade.mqh”, this one comes with MQL5 and it contains some trading functions. We need to create an instance from the class: “CTrade” that will be called: ”trade” and we are going to use it to open positions later on.
Inside of the “OnTick” function we calculate the Ask price and the Bid price, that’s done by using “SymbolInfoDouble” for the current symbol on the chart, “SYMBOL_ASK” will give us the Ask price while “SYMBOL_BID” will give us the Bid price and with “NormalizeDouble” and “_Digits” we calculate the right number of digits after the decimal point.
We also need to create a string for the signal, that string variable will also be called: ”signal” and so far we don’t have any value because that is going to be calculated later.
Let’s create an array for the price data that will be called: “PriceInformation” and we use “MqlRates” to create it because “MqlRates” is the structure that stores the information about prices, volumes and spread. We sort the array downwards from the current candle by using “ArraySetAsSeries” and with “CopyRates” we fill the array (PriceInformation) with price data for the current symbol on the chart and the currently selected period. We start with the current candle 0 (zero) and we need price data for 3 candles – that’s enough – and store the result in our price information array (PriceInformation).
Now let’s create another array called: “myPriceArray” this one is for the Expert Advisor data, the other one was for the candle prices.
The second array also needs to be sorted downwards by using “ArraySetAsSeries”.
Now we use the “iBearsPower” function that comes with MQL5 for the current symbol and the currently selected period on the chart, the last parameter 13, is the number of candles that you also will see when you drag the Bears Power Oscillator on your chart.
Now we use “CopyBuffer” for the bears power definition (BearsPowerDefinition) that we have created here to calculate the values for buffer 0 (zero) – that’s the first buffer – from the current candle 0 (zero) for 3 candles and store the result in our price array (myPriceArray) that makes it possible to calculate the current array value by looking at candle 0 (zero) in our price array (myPriceArray) and we store a result in the bears power value (BearsPowerValue) and if the “BearsPowerValue” is above 0 we would consider that to be a buy signal so we assign the word: “buy” to our signal.
Otherwise if the “BearsPowerValue” is below 0 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 we have no open positions we use “trade.Sell” to sell 10 micro lot.
Otherwise if the signal equals buy and we have no open positions we would use “trade.Buy” and buy 10 micro lot.
Finally we create a chart output that is done by using the “Comment” function and we want to output the words: “The current signal is:” followed by the calculated “signal”.
Now let’s compile the code, we don’t have any errors and in that case we can click here or press F4 to go back to Metatrader.
In Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, you will select the “SimpleBearsPowerStandaloneEA”. Let’s also enable the visualization option here and start your test.
…and here is our little example at work, we have buy and sell signals, usually you would use the Bears Power Oscillator to filter another entry signal but now you know how to code a standalone Expert Advisor for Metatrader 5 and you have coded it yourself with a few lines of MQL5 code.

Download “MQL5 Tutorial - Simple Bears Power Standalone Expert Advisor”

SimpleBearsPowerStandaloneEA.txt – Downloaded 156 times – 1.71 KB