MQL4 TUTORIAL

MQL4 TUTORIAL BASICS – 132 STANDALONE BOLLINGER BANDS RSI EXPERT ADVISOR


Listen Later

In this video we are going to create an expert advisor that uses the bollinger bands to create a signal. And we also want to use the RSI filter to confirm the signal.   So let’s find out how to do that with MQL4.   To get started, please click on a little button here or press F4 on your keyboard.   Now you should see the Metaeditor.   And here we have a precoded version for this expert advisor. We start by using the Include function.   It will include two modules for the bollinger bands and the RSI that are coded here.   Inside of the ontick function we open a function that is called Check Entry Bollinger to create a trading signal.   And for the filter we open a function that is called Check Entry RSI.   This one is coded in the second module and only if the trading signal equals buy and if the filter also equals buy, we want to check if we have no open positions.   That would be the case when orders total delivers a return value of zero. And if all conditions are true, we use order send for the current symbol on the chart to open a buy trade for ten microlot.   In the other case, if the trading signal equals sell and if the filter also equals sell and we have no open positions, that’s when we want to use order send for the current symbol on the chart to create a sell trade for ten microlot.   At the end of the main module we use the comment statement to output the trading signal for the bollinger bands and the filter signal for the RSI filter.   And that’s it for the main module.   But these two functions here need to be created. So let’s continue with the bollinger bands entry. Our function is called Check Entry Bollinger.   And it will return a string value.   Therefore we create a string variable for the signal.   We don’t assign a value here because we are going to calculate that now. And to do that we need to use the ibands function that comes with MQL4 for the current symbol on the chart and the currently selected period on that chart.   We do it for 20 candles.   The standard deviation is two.   We don’t need a shift value here.   We calculate the results based on the close price. We use mode lower for the lower bollinger band or mode upper for the upper bollinger band. And here we have the candle number one. Now let’s repeat that for the last bollinger bands value.   And here we want to do the whole thing again.   This time we do it for candle two. And when the close price for candle two is below the last lower bollinger band and the close price for candle one is now above the lower bollinger band, that would mean we have a re-entry from outside the bollinger bands from below and that is considered to be a buy signal.   So we assign the word Buy to our signal.   In the other case, if the close price for candle two was above the last upper bollinger band, and if the close price for candle one is now below the upper bollinger band, that would be a sell signal.   And that’s when we assign the word sell to our signal.   Finally, we return our signal to the main module by using the return statement here.   That’s it for the signal.   Now let’s continue with the filter. To get the filter value we use the function checkentry RSI. That is coded in this module. It also returns a string value.   Once again we create a signal variable of the type string.   Now we use Irsi for the current symbol on the chart and the currently selected period on that chart. We calculate the value for 14 candles for the close price and we do it for the current candle.   That’s candle zero.   And if the RSI value is below 30, that would mean we have a buy signal.   And that’s when we assign the word buy to our signal.   In the other case, if the RSI value is above 70, that could be a sell signal.   And that’s when we assign the word sell to our signal.   Finally, we return the signal to our main module by using the return statement.   And now you need to save the include modules and compile the main module.
...more
View all episodesView all episodes
Download on the App Store

MQL4 TUTORIALBy MQL4 TUTORIAL