Introduction to Standalone Bollinger MACD Expert Advisor (00:00 – 00:02)

  • Introduction to creating an Expert Advisor that automatically trades a Bollinger Bands entry signal with a MACD Oscillator filter in MetaTrader 5.

Combining Bollinger Bands and MACD for Signals (00:02 – 00:20)

  • Explanation of how Bollinger Bands and MACD are popular indicators that can be combined to create buy and sell signals for automated trading with this standalone Expert Advisor.

Starting in MetaEditor for MQL5 Programming (00:20 – 00:26)

  • Instructions to open MetaEditor in MetaTrader for MQL5 programming.

Creating a New Expert Advisor (00:26 – 00:33)

  • Steps to create a new Expert Advisor from a template in MetaEditor, with the example file named ‘Standalone Bollinger MACD Expert Advisor’.

Including Trade.mqh and Initializing CTrade (00:33 – 00:41)

  • Including the ‘Trade.mqh’ file for simplified trading functions and creating an instance of the ‘CTrade’ class.

Importing Bollinger and MACD Modules (00:41 – 00:56)

  • Including separate modules for Bollinger Bands and MACD, which provide entry and filter signals, respectively.

Calculating Ask and Bid Prices (00:56 – 01:22)

  • Using ‘SymbolInfoDouble’ to calculate Ask and Bid prices for the current symbol on the chart.

Setting Up Price Array and Normalizing Digits (01:22 – 01:49)

  • Creating a price array with ‘MqlRates’ and sorting it with ‘ArraySetAsSeries’. Normalizing the number of digits behind the decimal point for currency pairs.

Filling Price Array with Data (01:49 – 02:05)

  • Using ‘CopyRates’ to fill the price array with data for the current symbol and period on the chart.

Calculating Current Price and Signals (02:05 – 02:23)

  • Calculating the current price from the close price of candle 0 and creating variables for trading and filter signals using ‘CheckEntryBollinger’ and ‘CheckEntryMacD’.

Executing Trades Based on Signals (02:23 – 02:48)

  • Executing buy or sell trades with ‘’ or ‘trade.sell’ based on the combined trading and filter signals, provided there are no open positions.

Displaying Signals on Chart and Testing (02:48 – 03:05)

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

Conclusion and Strategy Testing (03:05 – 03:25)

  • Conclusion with instructions for running a strategy test in MetaTrader 5 and an invitation to explore more source codes and the premium course on


In this video we are going to create an Expert Advisor that is able to automatically trade a Bollinger Bands entry signal and a filter for the MacD Oscillator in Metatrader5. Both indicators are very popular and can be combined to create buy and sell signals that can automatically traded with this standalone Expert Advisor. So let’s see how to do that in MQL5. Please open the MetaEditor. We start by creating a new Expert Advisor by clicking on File, New, Expert Advisor from template. Let’s continue, with the include function to include the file Trade.mqh which comes with MQL5. It provides simplified trading functions and we create an instance of the class CTrade so we can use them.


Afterwards we include two files for the entry and the filter signal. The first one is for the Bollinger Bands and it will give us a trading signal. The second one is for the MacD and it will give us a filter signal. Both files have been coded before as separate modules, so they can also be used for other Expert Advisors. If you want to save time and effort, you can go to where you can find the premium course and a lot of precoded source code files in the store. In the next step we need to calculate the Ask price and the Bid price. That can be done by using the function SymbolInfoDouble for the current Symbol on the chart. We use Symbol_Ask to calculate the Ask price and Symbol_Bid to calculate the Bid price. With NormalizeDouble and UnderscoreDigits we can calculate the number of digits behind the dot. Depending on the currency pair, that might be 3 or 5 digits.


With MqlRates we create an Array for prices, called PriceInfo. Inside of the Ontick function we use ArraySetAsSeries to sort our price array from the current candle downwards. Then we can use CopyRates to fill our price array with data. We do that for the current symbol and the currently selected period on our chart, starting from candle 0, for 3 candles and store the result in our price info array. Now let’s calculate the current price by looking at the close price of candle 0 in our price info array. We create a string variable for the Trading Signal and call the function CheckEntryBollinger to check for a buy or sell signal. And we do the same thing for a string variable called Filter and call the function CheckEntryMacD to get the filter signal. If the trading signal and the filter both return a buy signal and we have no open positions, we want to use to buy 10 Micro Lot. In the other case, if the trading signal and the filter both return a sell signal, we use trade.sell to sell 10 Micro Lot. Finally, we use the Comment statement to output the trading signal and the filter on our chart. Press F7 to compile the code, if that works without any errors, you can return to Metatrader by pressing the F4 key.


Okay, if everything went well, you should now have a working standalone Expert Advisor for the Bollinger Bands signal and the MacD filter. You can run a strategy test like this one by pressing Control and R in Metatrader5. If you want to improve your trading results, you can find the premium course and more source codes on and in our shop. Thank you for watching and I will see you in the next video.