Previous iRSI

 

Hello,

I am new to MT5, shifting over from MT4 and I am having some issues with last candle values on an indicator.

My EA looks to see if the 1H RSI of the last candle is higher than 4H RSI of the last candle.

I am wanting to know how to get the RSI of last candle similar to the MT4 way:  1Hrsi=iRSI(NULL,PERIOD_H1,14,PRICE_CLOSE,0) 

My code is:

int rsi1    =INVALID_HANDLE;
int rsi1    =INVALID_HANDLE;int rsi1    =INVALID_HANDLE;

int OnInit(){
  rsi1=iRSI(NULL,PERIOD_H1,14,PRICE_CLOSE); 
    if(rsi1 == INVALID_HANDLE){
     Print("Error creating RSI1 indicator");
     return (INIT_FAILED);
    }
  rsi2=iRSI(NULL,PERIOD_H4,14,PRICE_CLOSE);
     if(rsi2 == INVALID_HANDLE){
     Print("Error creating RSI2 indicator");
     return (INIT_FAILED);
     }

  rsi3=iRSI(NULL,PERIOD_D1,14,PRICE_CLOSE);
     if(rsi3 == INVALID_HANDLE){
     Print("Error creating RSI3 indicator");
     return (INIT_FAILED);
     }
  return(INIT_SUCCEEDED);
}   

double rsi1Get(const int index){
   double rsi1a[1];
   ResetLastError();
   if(CopyBuffer(rsi1,0,index,1,rsi1a)<0){
      PrintFormat("Failed to copy data from RSI1, error code %d", GetLastError()); 
      return(0);
   }
   return(rsi1a[0]);
}

double rsi2Get(const int index){
   double rsi2a[1];
   ResetLastError();
   if(CopyBuffer(rsi2,0,index,1,rsi2a)<0){
      PrintFormat("Failed to copy data from RSI2, error code %d", GetLastError());
      return(0);
   }
   return(rsi2a[0]);
}

double rsi3Get(const int index){
   double rsi3a[1];
   ResetLastError();
   if(CopyBuffer(rsi3,0,index,1,rsi3a)<0){
      PrintFormat("Failed to copy data from RSI3, error code %d", GetLastError());
      return(0);
   }
   return(rsi3a[0]);
}

 To try to get the RSI values:

rsi1Get(0);  //RSI of 1H on Current candle

rsi1Get(1); //RSI of 1H on Last candle

The problem I am having is that rsi1Get(1) doesn't work properly and in back testing when I have 3 different timeframe rsi's then the testing will take over 30 minutes to 1 hour for testing 1 year's worth of tick data, but if I change to rsi1Get(0) it will take under 30 minutes. With only 2 different RSI timeframes (1h and 4h for example) it's very fast like under 10 minutes. Does adding more buffers increase testing times exponentially?

 
  1. On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
              Timeseries and Indicators Access /  Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
  2. You must set the array to asSeries to get the proper index.
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
  3. More buffers, more work per tick.
  4. Don't mix apples and oranges.
Reason: