Help to Get Current Tick RSI value

 

Hi Guys can you please help i am trying to find current tick value on the RSI Here is my code so far:


int RSiHandle;
RSiHandle = iRSI(_Symbol,PERIOD_M1,14,PRICE_CLOSE);
double rsi [2];
CopyBuffer(RSiHandle,0,1,2,rsi);
double RSICurrent =(rsi[0]);
double RSIPrevious =(rsi [1]);

 
Your topic has been moved to the section: Technical Indicators — In the future, please consider which section is most appropriate for your query.
MQL5 forum: Expert Advisors and Automated Trading
MQL5 forum: Expert Advisors and Automated Trading
  • www.mql5.com
How to create an Expert Advisor (a trading robot) for Forex trading
 
  1. Dominique Van: i am trying to find current tick value on the RSI

    There is no such thing as a “current tick value on the RSI.” RSI is an indicator. There is only the current RSI value (current bar) and previous bar values. Previous ticks are irrelevant.
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

  2. RSiHandle = iRSI(_Symbol,PERIOD_M1,14,PRICE_CLOSE);
    CopyBuffer(RSiHandle,0,1,2,rsi);

    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)

 
Dominique Van:

Hi Guys can you please help i am trying to find current tick value on the RSI Here is my code so far:


I suppose you mean the current value of RSI, updated on last tick.

That value is the value of the open bar 0, so you need to use that bar index as starting value in your CopyBuffer statement, not 1.

 
William Roeder #:
  1. There is no such thing as a “current tick value on the RSI.” RSI is an indicator. There is only the current RSI value (current bar) and previous bar values. Previous ticks are irrelevant

You are wrong, what about value you can see in top left corner of RSI indicator window? It updates around 10 times a second
 
Alain Verleyen #:

I suppose you mean the current value of RSI, updated on last tick.

That value is the value of the open bar 0, so you need to use that bar index as starting value in your CopyBuffer statement, not 1.

You are also wrong, if you CopyBuffer every single second for 60 seconds you will get same value every single time. Velue changes only on new bar open even if you ask for value of "bar Zero" 
 
otherek #:
You are also wrong, if you CopyBuffer every single second for 60 seconds you will get same value every single time. Velue changes only on new bar open even if you ask for value of "bar Zero" 

Of course not.

   if(CopyBuffer(rsiHandle,0,0,2,rsiValues)==2)
     {
      ...
     }


 
int handle_rsi;
double rsi_array[3];

void OnInit(){
   handle_rsi = iRSI (NULL, PERIOD_CURRENT, 14, PRICE_CLOSE);
   EventSetTimer(1);}


int cunter=0;

void OnTimer(){
   cunter++;
   CopyBuffer(handle_rsi,0,0,3,rsi_array);
   Comment("rsi_array[0] = ",rsi_array[0],"\n",cunter," sec");
   Print("rsi_array[0] = ",rsi_array[0]);}
what am i doing wrong?? please read screenshot and remember im Copying Buffer and printing value every single second
it's M1 period btw

example
 
otherek #:
what am i doing wrong?? please read screenshot and remember im Copying Buffer and printing value every single second
it's M1 period btw

rsi_array[0] in your code is the value of closed candle index 3.

You should use rsi_array[3] or use ArraySetAsSeries(rsi_array,true).

 

Here is the solution:

//+------------------------------------------------------------------+
//|                                                  IND_TEST_RP.mq5 |
//+------------------------------------------------------------------+
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0

//+------------------------------------------------------------------+
//| Declaration of variables                                         |
//+------------------------------------------------------------------+

   int i_COUNT, i_HANDLE, i_MA_PERIOD, i_START_POS;
   double db_ARRAY_RSI[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   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[])
{
   i_MA_PERIOD = 14;
   i_HANDLE = iRSI(Symbol(), PERIOD_CURRENT, i_MA_PERIOD, PRICE_CLOSE);
   i_START_POS = 0;
   i_COUNT = 1;
   
   CopyBuffer(i_HANDLE, 0, i_START_POS, i_COUNT, db_ARRAY_RSI);
   
   Comment("db_ARRAY_RSI[0]: ", NormalizeDouble(db_ARRAY_RSI[0], 2));
    
   return(rates_total);
}
//+------------------------------------------------------------------+

I recommend this article about the CopyBuffer function.

https://www.mql5.com/en/docs/series/copybuffer


If you want to have two values, the previous and the current one, then:

i_COUNT = 2;

Then:

db_ARRAY_RSI[0]   // Previous value
db_ARRAY_RSI[1]   // Current value
Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
  • www.mql5.com
CopyBuffer - Timeseries and Indicators Access - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
ra121pl #:

Here is the solution:

I recommend this article about the CopyBuffer function.

https://www.mql5.com/en/docs/series/copybuffer


If you want to have two values, the previous and the current one, then:

Then:

Your "solution" brings nothing new as I had already answered, and your code is not reliable as getting the RSI handle in OnCalculate() is a bad idea and you don't have any error handling.
Reason: