Wrong values for close, open, low, high arrays in MetaTrader 5

hsharghi  

I was getting wrong values in OnCalculate() method in my custom indicator. 

Here is a test indicator just logging the values. 


int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int startPos = rates_total-prev_calculated-1;
   for(int pos=startPos; pos>=0; pos--)
     {
      Print("pos: ", pos, " | close: ", close[pos], " | open: ", open[pos]);
      Print("pos: ", pos, " | low: ", low[pos], " | high: ", high[pos]);
     }
   return(rates_total);
  }

and the log output is:

log output


as it can be seen, the prices are not correct and not even near to the current market price. 

I've test with other charts and the values are not the same but they are wrong too.


Any help would be appreciated.

Regards,

Alain Verleyen  
There is nothing wrong. Index 0 is the OLDEST bar, not the current one, as the arrays are not indexed as series by default in MT5.