How to use Predefined Indicator for MultiPair EA?

[Deleted]  
fRSI(SelectedSymbol, PERIOD_CURRENT, 14, PRICE_CLOSE, 0);

double fRSI(string sy,ENUM_TIMEFRAMES SelectedTimeFrame,int period,ENUM_APPLIED_PRICE applied_price,int shift)
  {
   double buf[1];
   int handle=iRSI(sy,SelectedTimeFrame,period,applied_price);
   if(handle<0)
     {
      OpenNewTrade = false;
      return(0);
     }
   else
     {
      if(CopyBuffer(handle,0,shift,1,buf)<0)
        {
         OpenNewTrade = false;
         IndicatorRelease(handle);
         return(0);
        }
     }
   IndicatorRelease(handle);
   return(buf[0]);
  }

List of Indicator : https://www.mql5.com/en/docs/indicators/irsi


For example, i made function for RSI. is this right way to use for multi-currency pair EA? 

 

The logic is correct, but opening and releasing the handle inside fRSI() on every call is wasteful, worse on a multi-pair EA where this runs once per symbol per tick. iRSI() returns the same handle if one's already open for that symbol/timeframe/period, but calling IndicatorRelease() right after every read closes it immediately, so the next tick has to rebuild the indicator from scratch. Caching the handle instead avoids that:

int rsiHandles[]; // built once per symbol in OnInit, released once in OnDeinit

double fRSI(int handle, int shift)
{
   double buf[1];
   if(CopyBuffer(handle, 0, shift, 1, buf) <= 0) return 0;
   return buf[0];
}

Open each handle once, store it, and only release it in OnDeinit().