trouble indexing a buffer

 

I am coding an EA in MQL4 that uses a custom indicator.

In the EA, on each new Bar I am trying to fetch data from an array that is implemented in the custom indicator:

double value_z0 = getData(0); // current bar 

double value_z1 = getData(1); // last bar

double value_z2 = getData(2); // 2 bars ago

In the CI, the getData function is implemented:

double getData(int pSample)

{

    value = buffer[pSample];

    return value;

 }

Problem: The same value is returned for each of the getData calls , however, I know from my chart, that the values are different.

My buffer is set as a series (i.e., ArraySetAsSeries(buffer,true); 

 

Any help? This is supposed to be elementary ... I have less hair now :-( 

 

Joe