iRSIOnArray
Calculates the Relative Strength Index indicator on data, stored in array, and returns its value.
double iRSIOnArray( |
Parameters
array[]
[in] Array with data.
total
[in] The number of items to be counted. 0 means the whole array.
period
[in] Averaging period for calculation.
shift
[in] Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).
Returned value
Numerical value of the Relative Strength Index indicator, calculated on data, stored in array[].
Note
Unlike iRSI(...), the iRSIOnArray() does not take data by symbol name, timeframe, the applied price. The price data must be previously prepared. The indicator is calculated from left to right. To access to the array elements as to a series array (i.e., from right to left), one has to use the ArraySetAsSeries() function.
Example:
if(iRSIOnArray(ExtBuffer,1000,14,0)>iRSI(NULL,0,14,PRICE_CLOSE,1)) return(0); |
I tried but i have a problem to display the right data. I'll put my code here and explain:
With the code below, I can correctly display the "BufferRatio" indicator (as shown in the screenshot below):
"Capture 1"
#property copyright "jiyu" #property link "https://www.mql5.com" #property version "1.00" #property strict #property indicator_separate_window #property indicator_buffers 1 #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 3 double BufferRSI[]; double BufferRatio[]; extern string sym1 = "NDX100"; extern string sym2 = "SPX500"; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { IndicatorBuffers(2); SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(1, BufferRSI); SetIndexBuffer(0, BufferRatio); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { int counted_bars=IndicatorCounted(); for(int i=0;i<counted_bars;i++) { BufferRatio[i] = iClose(sym1, 0, i) / iClose(sym2, 0, i); BufferRSI[i] = iRSIOnArray(BufferRatio, 50, 14, i); } return(rates_total); }
But i want to display the indicator "BufferRSI", so i tried to switch the "SetIndexBuffer" like this:
SetIndexBuffer(0, BufferRSI); SetIndexBuffer(1, BufferRatio);
Result: "Capture 2"
https://ibb.co/NCsxp2q
My indicator stay to zero... I don't know how to display "BufferRSI"?? I think that my calculation "iRSIOnArray" is ok (but i'm not sure...)
HELP :'(
Thanks! The values are calculated correctly in the debug mode :)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I try to calculate an indicator using RSI (and then use it in an EA). But I don't want to apply the RSI to a symbol, I need to apply the RSI to a calculation I'm doing between different instruments. For the example, I am calculating a ratio between 2 symbols: DowJones and Nasdaq.
ratio = DJ/NQ
And then I want to calculate the RSI on this ratio: indicator = RSI( ratio, 14)
But how can I do that? Because in the RSI you can only put a symbol...
Thanks in advance for your help :)