How to use iRSI function to get the value of RSI on the last bar in a chart - page 2

Keith Watford  

Bodhi Mantra #:

William Roeder #:

Of course, it does.

  1. What does iRSI return?
  2. Why are you calling it outside of OnInit?


You want the rsi value ontick why would anyone want the rsi Oninit  <Deleted>?

Please respect other forum users and stop name-calling.

In this case you have succeeded in making yourself look foolish as iRSI should only be called in OnInit to get the handle.

CopyBuffer is called to get the RSI value for a particular bar and that may be done in OnTick.

Bodhi Mantra  

II know this is 7 years old but just to have a documented solution here in the thread I will post the code

double RSIArray[];
int rsi=iRSI("AUDJPY",PERIOD_M15,14,PRICE_CLOSE);
ArraySetAsSeries(RSIArray,true);
CopyBuffer(rsi,0,0,14,RSIArray);
   
printf("rsi = "+RSIArray[0]); 

Apparently mql5/metatrader5 is now using arrays or a database or something and storing the values of indicators there and to access them you need the "primary key" of that indicator type. For rsi it is 10 apparently and when you were trying to print the rsi value what you were actually printing was the rsi indicator key that is used to get the values to store into an array. Once in the array obviously slot 0 is that tick and you can shift back previous tick values as far as they will allow you to go. 

Vladimir Karputov  
Bodhi Mantra # :

II know this is 7 years old but just to have a documented solution here in the thread I will post the code

Apparently mql5/metatrader5 is now using arrays or a database or something and storing the values of indicators there and to access them you need the "primary key" of that indicator type . For rsi it is 10 apparently and when you were trying to print the rsi value what you were actually printing was the rsi indicator key that is used to get the values to store into an array. Once in the array obviously slot 0 is that tick and you can shift back previous tick values as far as they will allow you to go. 

Your code contains a gross error: according to the MQL5 style, the indicator handle must be received in OnInit!!!.

William Roeder  
Bodhi Mantra #: II know this is 7 years old but just to have a documented solution here in the thread I will post the code

You have no solution, as answered in this thread four (4) times (#7, #8, #9, #11).

Perhaps you should read the manual, especially the examples.
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
          How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
          MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
          How to call indicators in MQL5 - MQL5 Articles (2010)