René Balke's MT4 Programming Lessons (continued)
So, to summarize the first nine minutes from René Balke’s fourth video (see Post #81), if I am going to use an EA that relies on the RSI, I am going to need the OnTick function to look at the RSI's corresponding values with each new tick, and to do that, I am going to make the request (or query) between the OnTick function's opening and closing braces { }. Or more specifically, I am going to type code in the form of…
double rsi = iRSI(const string symbol,int timeframe,int period,ENUM_APPLIED_PRICE applied_price,int shift)
All that "stuff" between the parentheses is information I have to provide so that the expert advisor knows what manner of RSI I want to calculate, because when attaching an indicator to a chart, it might have several different options for its inputs (but as it turns out, the RSI only has one input—the period).
However, in addition to the inputs, indicators also have a number of other parameters that are required to call the indicator function (to get the indicator's corresponding data).
So, in the case of the RSI, the first of all the parameters is the symbol (i.e., const string symbol).
So, if I attach the expert advisor to the Euro-US dollar chart, for example, I will want that same chart’s corresponding data. Of course, this is kind of obvious, except that if I wanted to, I could opt to calculate the RSI of the GBPUSD instead of the EURUSD, even though the expert advisor is running on the EURUSD chart. So, this is what the first parameter is for. I get the symbol of the corresponding chart by typing an underscore (underline) followed by the word "symbol" (i.e., _Symbol). This holds the name/symbol of the underlying chart to which the expert advisor is attached.
The next parameter is the time frame, which is identified by the corresponding minutes/integer such as 1, 5, 15, 30, etc. However, because it would be kind of difficult to calculate the number for…say…weekly charts, there are also enumerations that can be used instead (i.e., ENUM_TIMEFRAMES) which are found here:
https://docs.mql4.com/constants/chartconstants/enum_timeframes
To specify the timeframe of the underlying chart, the correct ENUM to use is PERIOD_CURRENT. (Note that to enumerate means "to mention a number of things one by one.")
The next parameter required is the period, with the standard value used by the RSI indicator being 14. The parameter required after this is the applied price, with the RSI standard being the closing price, which is to say, PRICE_CLOSE. There are also numerical values that can be used here instead, but using the format just cited is a lot clearer.
And finally, there is the shift value. Since I ceased shifting values several years ago, I am likely to always set this value to zero (0).
By the way, the shift value is the number that identifies the bar (candlestick). The very last candle always has the number zero. The next value to the left will have the number one, and so on, with every single bar (number) having its own RSI value.
The reason a coder might need the shift value is to identify exactly which bar it is from which they want to retrieve the desired RSI value(s) (if it isn't the current bar).
(Note that it is because the readings on the RSI indicator are expressed as decimal numbers between 0 and 100 that the iRSI function is categorized as a double.)
So, to summarize the first nine minutes from René Balke’s fourth video (see Post #81), if I am going to use an EA that relies on the RSI, I am going to need the OnTick function to look at the RSI's corresponding values with each new tick, and to do that, I am going to make the request (or query) between the OnTick function's opening and closing braces { }. Or more specifically, I am going to type code in the form of…
double rsi = iRSI(const string symbol,int timeframe,int period,ENUM_APPLIED_PRICE applied_price,int shift)
All that "stuff" between the parentheses is information I have to provide so that the expert advisor knows what manner of RSI I want to calculate, because when attaching an indicator to a chart, it might have several different options for its inputs (but as it turns out, the RSI only has one input—the period).
However, in addition to the inputs, indicators also have a number of other parameters that are required to call the indicator function (to get the indicator's corresponding data).
So, in the case of the RSI, the first of all the parameters is the symbol (i.e., const string symbol).
So, if I attach the expert advisor to the Euro-US dollar chart, for example, I will want that same chart’s corresponding data. Of course, this is kind of obvious, except that if I wanted to, I could opt to calculate the RSI of the GBPUSD instead of the EURUSD, even though the expert advisor is running on the EURUSD chart. So, this is what the first parameter is for. I get the symbol of the corresponding chart by typing an underscore (underline) followed by the word "symbol" (i.e., _Symbol). This holds the name/symbol of the underlying chart to which the expert advisor is attached.
The next parameter is the time frame, which is identified by the corresponding minutes/integer such as 1, 5, 15, 30, etc. However, because it would be kind of difficult to calculate the number for…say…weekly charts, there are also enumerations that can be used instead (i.e., ENUM_TIMEFRAMES) which are found here:
https://docs.mql4.com/constants/chartconstants/enum_timeframes
To specify the timeframe of the underlying chart, the correct ENUM to use is PERIOD_CURRENT. (Note that to enumerate means "to mention a number of things one by one.")
The next parameter required is the period, with the standard value used by the RSI indicator being 14. The parameter required after this is the applied price, with the RSI standard being the closing price, which is to say, PRICE_CLOSE. There are also numerical values that can be used here instead, but using the format just cited is a lot clearer.
And finally, there is the shift value. Since I ceased shifting values several years ago, I am likely to always set this value to zero (0).
By the way, the shift value is the number that identifies the bar (candlestick). The very last candle always has the number zero. The next value to the left will have the number one, and so on, with every single bar (number) having its own RSI value.
The reason a coder might need the shift value is to identify exactly which bar it is from which they want to retrieve the desired RSI value(s) (if it isn't the current bar).
(Note that it is because the readings on the RSI indicator are expressed as decimal numbers between 0 and 100 that the iRSI function is categorized as a double.)
Last edited: