Expert Advisor values from Indicator do not match chart values

 

Hello. I am trying to code my first Expert Advisor in MQL5, and I am having an issue getting the correct values from indicators, specifically RSI and ATR in my case.

This is the code I am using:

int atrHandle;
int rsiHandle;

atrHandle = iATR(NULL, 0, ATR_Period);
rsiHandle = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE);

double atrBuffer[];
CopyBuffer(atrHandle, 0, 0, 1, atrBuffer);
double atr = atrBuffer[0];

double rsiBuffer[];
CopyBuffer(rsiHandle, 0, 0, 1, rsiBuffer);
double rsi = rsiBuffer[0];

And as you can see from this screenshot, I am getting different values from the indicator on the chart and the EA.


I have been trying to figure this out for a while, and I am stuck. Does anyone know the issue? I would really appreciate a helpful eye.

 
You have to change the direction of arrays. By default zero refers to the farthest bar in history. 
Use ArraySetAsSeries to set the flag to true.