How to Create a Simple But Profitable Bollinger Bands Expert Advisor in MQL4
When I started with automated trading, I was looking for the very best indicator I could find. Today, I know indicators are totally overrated but if I had to choose one, it would be Bollinger Bands. In case you don’t know what that is, this indicator will show 3 lines and most of the time, the price will stay within these lines. But if it breaks out like here and it does a re-entry, we want to open a trade.
In our case, the period value would be 20 and the deviation value would be 2. First of all, we will create a new expert advisor from a template and call it CheckBollingerBands(). In the OnTick() function, we will call CheckBollingerBandTrade() – the only other function – and here you can find the BollingerBand Period and BollingerBand deviation we just defined. These two lines will calculate the lower and upper BollingerBands for the last candle. And these two lines will calculate previous BollingerBands.
Here, we will check if the current lowest price is higher than the lower BollingerBand and if the lowest price was below the previous lower BollingerBand before. And if we do not have any open trades, we want to buy. In the other case, if the highest price of the last candle is below the upper BollingerBand and if the highest price of the candle before was above the previous BollingerBand, we are going to sell.
Very simple EA, but you will love the results. Please press F4 and start your back test. Okay, I will speed up things a little bit here, but as you can see, we have a sell trade here because there was a re-entry from the upper BollingerBand. Let’s see the results. And this one is below the lower BollingerBand so it’s a buy trade. So far, the results are pretty amazing. Let’s see the results for a whole year. Okay, our total net profit is 58 dollars and 66 cents.