LEARN MQL5 TUTORIAL BASICS - 22 HOW TO CODE AN RSI EXPERT ADVISOR

Published: 01 January 1970
on channel: MQL5 Tutorial
12,496
183

https://mql5tutorial.com/?s=rsi

Introduction to Creating an RSI Trading Expert Advisor in MQL5 (00:01 – 00:16)

Introduction to the tutorial on creating an Expert Advisor for trading the Relative Strength Index (RSI) using MQL5.
Opening MetaEditor and Creating a New Expert Advisor File (00:16 – 00:38)

Instructions on opening MetaEditor and creating a new Expert Advisor file named "SimpleRSIEA".
Setting Up the Code Structure and Including Trade.mqh (00:38 – 01:01)

Removing unnecessary code and including the 'Trade.mqh' file for trading functions.
Calculating Ask and Bid Prices (01:01 – 01:29)

Using 'SymbolInfoDouble' to calculate the Ask and Bid prices and normalizing them for currency pair precision.
Creating a Variable for the Signal and Price Array (01:29 – 02:06)

Initializing a variable for the trading signal and creating an array for price data called "myRSIArray".
Defining RSI Properties and Filling the Price Array (02:06 – 03:27)

Defining properties for the RSI and using 'CopyBuffer' to fill the price array with RSI data.
Determining Buy and Sell Signals Based on RSI (03:27 – 04:39)

Setting conditions for buy and sell signals based on the RSI value relative to overbought and oversold levels.
Executing Trades Based on Signals (04:39 – 05:06)

Using 'trade.Sell' and 'trade.Buy' to execute trades based on the determined signals.
Displaying the Current Signal on the Chart (05:06 – 05:18)

Using the 'Comment' function to display the current trading signal on the chart.
Compiling the Code and Testing in MetaTrader (05:18 – 05:45)

Compiling the code and testing the Expert Advisor in MetaTrader using the Strategy Tester.
Observing the RSI EA in Action on the Chart (05:45 – 07:00)
Watching the Expert Advisor trade the RSI on the chart and analyzing its performance.
This overview provides a detailed summary of the video's content, organized into specific chapters with corresponding timestamps.


In this video, we are going to create an Expert Advisor to automatically calculate and trade the Relative Strength Index also called RSI, so let's find out how to do that with MQL5.
First you need to click on the little button 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 (template)” from template, “Continue”, I will call this file: “SimpleRSIEA”, click on “Continue”, “Continue” and “Finish”.
Now you can delete everything above the “OnTick” function and the two comment lines here.
We start with an include statement, we want to include the file: “Trade.mqh”, it comes with trading functions and it is included in MQL5, so now we can create an instance called: “trade”.
Inside of the “OnTick” function we want to calculate the Ask price and the Bid price because we are going to buy and sell, so we use “SymbolInfoDouble”, “_Symbol“, “SYMBOL_ASK” to calculate the Ask price and with “SymbolInfoDouble”, “_Symbol“, “SYMBOL_BID” – all in capital letters – we will get the Bid price.
“NormalizeDouble” and “_Digits” is a way to automatically calculate the number of digits behind the dot because the “_Digits” variable stores the number of digits after the decimal point that might be 3 digits – like in this case – or 5 digits.
Let's create a variable for the signal, the name is also “signal”, please don't assign a value right now because we need to calculate that.
We need to create an array for the price data that will be called: “myRSIArray”, it's a double array, so let's define the properties of the RSI (myRSIDefinition), we have an included function in MQL5 that is called: “iRSI”, it takes a few parameters;
The first parameter is for the current symbol on the chart,
The second one for the period,
This value; 14, is also what you see if you click on: “Insert/ Indicators/ Oscillators/ Relative Strength Index”, here you have a period value for 14 candles and it is applied to the close prices.
This is how the Indicator looks like.
Until the last major update, it was automatically shown on the chart whenever I calculated it, but now I need to right-click into the chart, select “Templates/ Save Template” and save it as: “tester.tpl” because this is the template that is going to be used in the backtest and the default template is the one that you will see when you drag any Expert Advisor on the chart, so let's choose “tester.tpl” and save it.
Yes, I want to override it, so this parameter is for the period,
This one is to calculate values based on the close price.
Now I use “CopyBuffer” to fill the price array (myRSIArray) that we have created here with data according to the definition (myRSIDefinition) that we made here.


Watch video LEARN MQL5 TUTORIAL BASICS - 22 HOW TO CODE AN RSI EXPERT ADVISOR online without registration, duration hours minute second in high quality. This video was added by user MQL5 Tutorial 01 January 1970, don't forget to share it with your friends and acquaintances, it has been viewed on our site 12,496 once and liked it 183 people.