In this video, we are going to create an expert advisor entry signal for this little oscillator here. It is called the Relative Strength Index, and it’s very popular. So let’s find out how we can do that with MQL5.
The RSI oscillator is drawn in a separate window below the candle chart.
It only has one line, which will be our entry signal.
Most of the time, oscillators are used to make filters, but they can also be used to make entry signals, which is what we will do here.
To use it, we make a separate MQ5 file and put it in the same directory as the other Platin System files.
CheckEntry RSI.mq5 is the name of the file, and it only has one function called CheckEntry.
It will calculate what our entry signal is and send that result back to the main module.
We want to make a string variable for the signal file, but we won’t give it a value yet because it will be worked out later.
So, we build a double-type array to hold the different prices.
In the next step, we’ll use the function iRSI, which is part of the MQL5 programming language. And we can use it to define our oscillator.
Four parameters need to be passed.
The first parameter is the symbol on the chart that is selected at the moment.
The second parameter is the time range we’ve chosen on that chart.
The third parameter is for the number of candles that we want to calculate. In our case we use 14 candles.
The fourth parameter is used to define what we want to use for the result. In our case we calculate it for the close price.
The next step is to sort our array by using Array Set As Series. We want to put it in order from the current candle down.
And now, thanks to CopyBuffer, we can fill the price array with the data for the prices.
The first parameter is for the definition we made above.
Parameter 2 is for the first buffer, which is the oscillator’s signal line.
Candle 0 is used for parameter 3, which is the number of the current candle.
The number of candles we want to use in the calculation is the fourth parameter. We use three candles.
And the price array is the last parameter. This is where we want to store these values.
We only need to look at the value for candle 0 in our price array to find the value for the current candle.
With NormalizeDouble and the number 2 we can create a number with two digits.
If that number is greater than 70, we call that a “sell” signal and put the word “sell” into our signal.
If it is below 30, however, we give our signal the word “buy.”
Lastly, we use the return function to send the calculated value back to our main module.
Don’t forget to save the file, please.
You don’t have to compile it! Jjust save it and go back to the main module, where the OnTick function is included.
There, you need to add the new file to the import section. You can do this by using the include statement.
Please uncomment any other entry signals and press F7 or click the Compile button to compile the main module and the new entry file you just made.
Okay, you should now have a version of the oscillator that works. This version is called the RSI oscillator.
You can use it in your own system, or if you have the Platin System or the Robot Trading system, you can import it into those.
By the way, a demo version is now available on PlatinSystem.org.
That’s all for now.
Thank you for watching, and I’ll see you in the next video.
Okay. I hope the compilation process worked for you. If that is the case, you should have a working version for the RSI that you can use to create signals, or you can use it as a filter. For now, I say thank you for watching, and I will see you in the next video.