Buffer: direct calculation or variable create different results.

[Deleted]  

Hi everyone, the following two codes should produce the same result but only the second one works as intended. Someone can explain me why? 

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 lookback = 1000; 
   for(int iBar = Bars-1-MathMax(lookback, prev_calculated); iBar >= 0; --iBar)
     {

    int indx = iBarShift(NULL,60,Time[iBar],false);
    open_1[iBar] = iOpen(NULL,60,indx);
  
  	}
return(rates_total-1);
  }

The code above produce completely wrong results. Instead the following will work:

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 lookback = 1000; 
   for(int iBar = Bars-1-MathMax(lookback, prev_calculated); iBar >= 0; --iBar)
     {
    
    int indx = iBarShift(NULL,60,Time[iBar],false);
    double tf_ = iOpen(NULL,60,indx);
    open_1[iBar] = tf_;


  }
return(rates_total-1);
  }

Hope I've explained myself weel. I just want to understand why results are not equal. 

 
ironhak: I just want to understand why results are not equal. 
    int indx = iBarShift(NULL,60,Time[iBar],false);

You started the download of the H1 with the first, but didn't wait. If you ran it a second time, you would have gotten the correct results.

On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
          Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)