envelope calculation on RSI

 
Good evening guys, I am creating an EA but I have a problem with the calculation of Envelopes on the RSI:
Assuming that the function iEnvelopes() cannot operate on the RSI but only on a chart then on a price, then I make the function iEnvelopesOnArray() where I give it as input an array of the N passed RSI that I have constructed before. All this works and returns values that are plausible but not equal to the envelope calculated with the indicators that are already on the mt4. I cannot understand why they are not equal. 

This is the code

input string RSI_symbol = NULL;
input int RSI_timeframe = 0;
input int RSI_applied_price = PRICE_CLOSE;
input int RSI_period = 16;
input int IND_RSI_MEM = 100;

double rsi;
double rsi_array[];

void GetLastRSIValues(double &array[]){
   for (int i = 0 ; i < IND_RSI_MEM ; i++ )
   {
      ArrayResize(array,IND_RSI_MEM);
      array[i] = iRSI(RSI_symbol,RSI_timeframe,RSI_period, PRICE_CLOSE,i);
   }return;}

int start(){

rsi = iRSI(RSI_symbol,RSI_timeframe,RSI_period,RSI_applied_price,0);
ArrayInitialize(rsi_array,0);
GetLastRSIValues(rsi_array);
ArraySetAsSeries(rsi_array,true);
env=iEnvelopesOnArray(rsi_array,0,IND_RSI_MEM,MODE_SMMA,0,0,MODE_MAIN,0);
return(0);}

And this is how I compute the Envelope on RSI on my mt4 (images attached):

File:
rsi.png  9 kb
envelopes.png  9 kb
Motivazione: