Is it possible to get iRSI value in a timeframe other than that of the chart?

 

Hi,

Is it possible to get the value of iRSI in a timeframe (such as daily) when the chart's timeframe is weekly?

Thanks 

 
of course you set the time frame in the software you can get all frames if you want.
 
Marco vd Heijden:
of course you set the time frame in the software you can get all frames if you want.

I did it in the following indicator and it did not work, I attached following indicator to a chart and it comments the value of iRSI correctly in timeframe H4, but when I switch the chart's timeframe to Weekly, it does not show the value of iRSI correctly.

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
double iRSIBuffer[];
//+------------------------------------------------------------------+
//| 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[])

      
{
         CopyBuffer(iRSI(_Symbol,PERIOD_H4,14,PRICE_CLOSE),0,0,1,iRSIBuffer);
         double irsiv = iRSIBuffer[0];
         Comment (irsiv);

         if(irsiv<30.00)
         {
            Alert("Buy");
         }         
      
   return(rates_total);
}

Please help me.

Thanks 

 
MT5.2014:

I did it in the following indicator and it did not work, I attached following indicator to a chart and it comments the value of iRSI correctly in timeframe H4, but when I switch the chart's timeframe to Weekly, it does not show the value of iRSI correctly.

Please help me.

Thanks 

irsi_handle=iRSI(_Symbol,PERIOD_H4,14,PRICE_CLOSE),0,0,1,iRSIBuffer);
CopyBuffer(irsi_handle,0,0,to_copy,iRSIBuffer);

I'm not sure but i think you first get the handle and then translate that into the actual value.

Maybe Alain can help.

 
Marco vd Heijden:

I'm not sure but i think you first get the handle and then translate that into the actual value.

Maybe Alain can help.

Technically there is no problem with this code.

But you are right, it's recommended to get an handle (in OnInit()), once for all.

 
MT5.2014:

I did it in the following indicator and it did not work, I attached following indicator to a chart and it comments the value of iRSI correctly in timeframe H4, but when I switch the chart's timeframe to Weekly, it does not show the value of iRSI correctly.

Please help me.

Thanks 

It will always show the RSI value of H4 timeframe, whatever chart you run the indicator.

Try this (however this code is very bad, without any error checking) :

CopyBuffer(iRSI(_Symbol,PERIOD_CURRENT,14,PRICE_CLOSE),0,0,1,iRSIBuffer);
 
Alain Verleyen:

It will always show the RSI value of H4 timeframe, whatever chart you run the indicator.

Try this (however this code very bad, without any error checking) :

Thank you so much for your help, I changed the code a little bit, but it does not work in timeframes other than H4 (it returns 0), I want to have this indicator (giving the value of RSI in H4) attached to a chart with weekly timeframe. I think I am doing something wrong.

Another issue is that it alerts twice, I do not know why, please help.

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
double iRSIBuffer[3];
//+------------------------------------------------------------------+
//| 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[])
{
         int iRSIhandle = iRSI(_Symbol,PERIOD_H4,14,PRICE_CLOSE);
         CopyBuffer(iRSIhandle,0,0,3,iRSIBuffer);
         double irsival=NormalizeDouble(iRSIBuffer[2],2);
         Comment (irsival);
         if (irsival!=0 && irsival<30.00) Alert(irsival);

return(rates_total);
}

 Thank you

Reason: