MQL5 Tutorial

MQL5 TUTORIAL BASICS – 132 STANDALONE BOLLINGER BANDS RSI EXPERT ADVISOR


Listen Later

In this video we are going to create an Expert Advisor like this one that is able to trade the Bollinger Band signal and it also uses the RSI Oscillator as a filter.   So let’s find out how to do that with MQL5.   To get started, please click on the little button here or press F4 on your keyboard.   Now you should see the meta editor window and here we have a pre coded version for the Bollinger Bands RSI Expert Advisor the first thing we do is to use the include function to include the file trade Mqh.   This one comes with MQL5 and it provides some simplified trading functions and we also use to include two more modules that we are going to create later on.   The first one is to check the entry for the bollinger bands and the second one is for the RSI Oscillator. We start by calculating the ask price and the bid price.   That is done by using symbol info double for the current symbol on the chart.   We either use symbol underscore ask or symbol underscore bit and with normalize double and underscore digits we make sure to calculate the right number of digits behind the dot, that is depending on the currency pair we use.   Now we use Ctrade to create an instance called trade. That will be used to open the trades later on. And we create an array called price info by using MQL rates.   We do that outside of the ontick function because we need the same thing here in the bollinger bands module and in the on tick function we start with array set as series.   To sort our price info array from the current candle downwards. Then we can use copy rates to fill our price info array for the current symbol on the chart and the currently selected period on that chart starting from candle zero for three candles.   And to calculate the current price we look into the price info array, especially at candles zero and at close price. Now let’s find out how to get the trading signal.   That can be done by using a function called check entry bollinger and this function exists in this module here.   It is called Check entry bollinger and it will give back a string value to our main module.   We start by creating a string variable for the signal.   Now we create three arrays for the middle, the upper and the lower band.   Array and we sort all three arrays by using array set as series.   Afterwards we use the built in iBands function of MQL5 for the current symbol on the chart and the currently selected period on the chart.   We want to calculate the values for 20 candles, no shift value and the deviation value is two.   The results will be calculated based on the close price.   Let’s continue to fill our arrays with copy buffer according to the bollinger bands definition that we have created above. We are going to do that for buffer zero.   That’s the middle band array, buffer one for the upper band array and buffer two for the lower band array.   All three values are starting from candle zero.   That’s the current candle and we want to copy the values for three candles and store them in the according arrays.   That makes it possible to get the current values for the middle band, the upper band and the lower band by looking at candle zero in the according arrays.   That will give us the price for the current candle and we do that again for candle one. That’s the candle before the current one.   And if the close price for candle one of our price info array was below the lower bollinger band, and if it is now above the lower bollinger band, that would mean we have a buy signal.   In the other case, if the close price for candle one was above the upper band, and if it is now below the upper band for kennel zero that would mean we have a sell signal and that’s when we assign the word sell to our signal.   And finally we return our signal to the main module. And that’s where we check the filter. By using a function check entry RSI, we can find that one in the second module.   It is called Checkentry RSI and it returns a string value.
...more
View all episodesView all episodes
Download on the App Store

MQL5 TutorialBy Raimund Bauer