Simple RSI Robot with MQL5


You have asked for it so here it is.
A YouTube subscriber with the name kasteren wanted me to create a video on how to create a simple Expert Advisor in MQL5 for the RSI indicator.
The RSI indicator simply tells you if the market is overbought or oversold.
So you want to enter if the price crosses the line here and go long or in the other case if the price is above the upper line and it crosses the line you want to go short.
So let’s stop the indicator for a while and look at the value here and place your mouse cursor over the line.
That will show you a value on it, 53.92 and in our little Expert Advisor we want to calculate it because if we can check if the RSI crossed this line, we could use that as an entry signal for a short trade and if it crosses this line it would be a signal for a long trade.
Now how can that be done?
To calculate the RSI, please click on this little button here or hit the F4 key to bring up the Meta Editor.
Now please select File, New, Expert Advisor from template, continue, we will give it the name simple RSI, continue, continue, finish.
Now delete everything above the OnTick function and the two comment lines here and the first thing we need is an array to hold our price data.
We will give it the name my RSI array. Afterwards we want to define the properties of the RSI, we will create a variable called my RSI definition by using MQL 5 built in function iRSI, for the current symbol the chart and the selected trading period.
We will calculate it for fourteen candles because this is the default value that is used by MetaTrader 5 if you attach the RSI indicator to your chart.
And we want to calculate the value based on the closed price.
Now we want to sort our array from the current candle downwards.
And then the next step we want to fill it by using the CopyBuffer function.
This is our definition, this is the buffer number zero because we only need to have one value to be calculated for this indicator.
This zero stands for the current candle, and we want to copy the price values for three candles into our price array for the RSI.
In the next step, we are going to calculate the Expert Advisor for the current candle.
It will be stored in the variable called my RSA value and it will be the value of the current candle, in the array my RSI array.
And in the last step we want to output the text my RSI value and the calculated value directly on our chart.
So let’s compile the Expert Advisor and we have no errors and no warnings.
So let’s hit the little button over here or press the F4 key to bring up the MetaTrader.
In the Meta Trader we want to use a little trick, click on insert, indicators, oscillators and select the relative strength index.
That’s the RSI, you see it has a value of fourteen and it is applied to the closed price.
That’s exactly what we have defined here in our little Expert Advisor so let’s hit the okay button.
Now right click on the template and select template, save template, and save it as Tester.tpl,.
That will make this template a default template for the strategy tester.
Now click on View Strategy Tester or hit control and R and select the simple RSI.ex5 file we have created.
Afterwards mark the visualisation option here and click on start.
So this is how it looks like, let’s pause the test.
This is 34.78 and that exactly matches the value of the RSI value.
So now you know how to calculate the RSI value to use it for your own entry and you did it within a few minutes by creating this little Expert Advisor here.

Download “MQL5 Simple RSI Expert Advisor from MQL5 Tutorial”

SimpleRSI.txt – Downloaded 396 times – 689.00 B