Okay you wanted me to do it so here it is.
A YouTube subscriber with the name UndercoverStudio asked me if I could create an Expert Advisor that could place a trade based on two indicators for example RSI and Bollinger bands.
Well, first of all please let me say that the more conditions you have the longer the Expert Advisor will get so in this case we will only check if the current ask price is below the Bollinger band and if the RSI indicator has a value below thirty, because below thirty the market is considered to be oversold.
And if this and this is true we want to output the text oversold and below lower band on the chart.
Now how can that be done with MQL5?
To create a new Expert Advisor please click on this little button or hit the F4 key, that will bring up the MetaEditor and here we select File, New, Expert Advisor from template, continue and we will give it the name simple RSI Bollinger entry.
Click on continue, continue, finish and delete everything above the OnTick function. Please also remove the two comment lines here.
Okay the first thing we need is an empty chart output so let’s use the comment function without any text.
In the next step we want to create two arrays one for RSI and one for lower Bollinger band.
Now we want to define our RSI settings. We will use the function IRSI for the current currency pair on the chart and the currently selected period and we will use fourteen candles and the closed price.
Afterwards we want to sort our price data from the current candle downwards.
This is done with the function arraysetasseries and now we want to fill it with data by using the copybuffer function with our definition from the current candle for three candles downwards.
And because the RSI only uses one line, we use the current buffer with the number zero.
And after all we want to calculate the value for the current RSI value and this is candle zero so it’s the current candle.
Let’s create a little separation line here because now we want to sort our price array for the lower band array of the Bollinger bands.
This is our definition for the Bollinger bands; it uses the iBands function for the current symbol on the chart and the selected period for twenty candles.
It has no shift and the deviation is two, we want to use the close prices.
Now we want to use copybuffer to fill the lower bands array according to our Bollinger band’s definition for the lower Bollinger band, this is the two here.
The middle band would a one and the upper band would be a zero.
We want to start from the current candle and we want to copy the information for the last three candles.
And because we used the close price we are going to calculate the lower band value for the last closed candle.
Let’s get the ask prize here by using symbolinfodouble because in our last step we want to check if the RSI value is below thirty.
So that would be the case if the blue line is below the dotted line here and we want to stack another if condition to find out if the current asked price is below the lower Bollinger value.
And if this is the case we use the comment function to print out the text oversold and below the lower band.
This is just the number of line feeds, so the text will appear in the middle of the chart.
Okay let’s compile the Expert Advisor, click this little button or hit the F4 key to bring up the Meta Trader, select View Strategy Tester or hit the control and the R key, and select the file simple RSI Bollinger entry.ex5 here.
Now mark the visualization option and hit the start key.
And this is what you should see, the current ask price is below the lower Bollinger band and the blue line of the RSI is below the dotted line.
So we see the oversold and below lower band text here on the chart. If one of the conditions fails the text will disappear.
Okay now you know how to stack IF conditions and how to check two different kinds of indicators to find out if your entry condition is true!
And you have all done it with this little Expert Advisor here.
Download “MQL5 Simple RSI and Bollinger Bands Expert Advisor from MQL5 Tutorial”SimpleRSIBollingerEntry.txt – Downloaded 554 times – 1.44 KB