MQL5 Tutorial

MQL5 TUTORIAL BASICS – 64 SIMPLE MULTI RSI


Listen Later

In this video we are going to create an expert advisor for the RSI indicator, in this case for multiple values in different time frames, so let’s find out how to do that with mql5. To get started please click on a little icon here or press F4 on your keyboard, now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file simple multi RSI, click on continue, continue and finish. Now you can delete everything above the ontick function and let’s also remove the two comment lines here. We start with an include statement to include the file trade dot mqh. Afterwards, we are going to create an instance of the class ctrade, this is called trade and we are going to use it to open positions later on. Inside of the ontick function we calculate the ask price and the bid price that is done by using symbol info double, for the current symbol we use either symbol ask or a symbol bid – all in capital letters – and with normalize double and underscore digits we automatically calculate the right number of digits behind the dot. Afterwards, we create an empty string called signal, we don’t assign a value here and now we need three arrays, one for the current time frame on the chart, one for the thirty-minute time frame and one for the sixty-minute time frame. Let’s define the current one, this is done by using the iRSI function for the current symbol on the chart and the currently selected period on that chart. We want to calculate the value for fourteen candles and the result should be calculated based on the close price. Let’s use array set as series to sort the RSI array for the current value, afterwards we use copy buffer for the current value that we have defined here and we store the values in the RSI current array and afterwards, we are able to calculate the current value. All we need to do is to get the value for the current candle zero out of our RSI array current and with normalize double we cut the result to show two digits because that is what the original RSI indicator also does and that’s it for the first value. Now we repeat the whole process to get values for thirty minutes, now we use the iRSI function for the current symbol on the chart but this time we are going to use period underscore m thirty and if you mark that and press F1 you will see that we have values for all the possible timeframes here, this one is for thirty minutes and this one is for one hour, so, for now, we use period underscore m thirty. Again we use array set as series to sort the RSI array for thirty candles, afterwards we use copy buffer according to the definition that we have created here and store the values inside of our RSI array thirty and to calculate the RSI value for thirty minutes we take a look at candle zero inside of our RSI array thirty and again we use normalize double and cut the result to have two digits behind the dot. To get the values for one hour we do the same again, this should be no surprise anymore we just use different variable names and this time we use period underscore h one, everything else is basically the same. And if all three values are above seventy that would mean that the blue indicator line here is above the upper dotted line for the seventy percent level, that would be a sell signal and now we would assign the word sell to our signal. If all three values are below thirty we would consider that to be a buy signal because that would mean that the signal line is below the lower dotted line here and that’s when we want to buy. So if the current signal equals sell and we get a return value that is below one for positions total that would mean that we have a sell signal and no open positions and now we use trade dot sell to sell ten micro lot. Otherwise, if the signal equals buy and we have no open positions we would use trade dot buy and buy ten micro lot. Finally, we use the comment statement to create a chart output for the current...
...more
View all episodesView all episodes
Download on the App Store

MQL5 TutorialBy Raimund Bauer