Bar shift issue, why this happen?

 

In the first code the condition open_b is verified, in the second never. The only difference is the bar shift, I need one more condition on the 0 bar so I incremented the bar by 1. Why this happen?


CODE 1:
//--------------Trading criteria------------------------------------------------- 5 --
  
    double open0 = iOpen(NULL,0,0);
    double close0 = iClose(NULL,0,0);
    double high0 = iHigh(NULL,0,0);
    double low0 = iLow(NULL,0,0);
    
    double open1 = iOpen(NULL,0,1);
    double close1 = iClose(NULL,0,1);
    
    double open2 = iOpen(NULL,0,2);
    double close2 = iClose(NULL,0,2);

    double open3 = iOpen(NULL,0,3);
    double close3 = iClose(NULL,0,3);
    
    double open4 = iOpen(NULL,0,4);
    double close4 = iClose(NULL,0,4);
    
    double open5 = iOpen(NULL,0,5);
    double close5 = iClose(NULL,0,5);

if (
    Ask<iBands(NULL,0,20,2,0,PRICE_MEDIAN,MODE_MAIN,0) &&   // price minore di linea media bollinger
    close4 < open4 &&                                       // down bar 4
    close3 < open3 &&                                       // down bar 3
    close2 < open2 &&                                       // down bar 2
    close1 < open1 &&                                       // down bar 1
    close3 > close2 &&                                      // down trend
    close2 > close1 &&                                      // down trend
    MathAbs(close0 - open0) < VolumeDoji * Point &&         // DOJI minore di...
    (
        (close0 > open0 && open0 - low0 > OMBRAlow * Point && high0 - close0 < OMBRAhigh * Point && MathAbs(open0 - low0) > MathAbs(close0 - open0)) ||  // Candela verde (up), low grande, high piccolo, ombra piu lunga del corpo
        (close0 < open0 && close0 - low0 > OMBRAlow * Point && high0 - open0 < OMBRAhigh * Point && MathAbs(close0 - low0) > MathAbs(close0 - open0))    // Candela rossa (down), low grande, high piccolo, ombra piu lunga del corpo
    )
   )
{
    Opn_B = true;
}






CODE 2:
//--------------Trading criteria------------------------------------------------- 5 --
  
    double open0 = iOpen(NULL,0,0);
    double close0 = iClose(NULL,0,0);
    double high0 = iHigh(NULL,0,0);
    double low0 = iLow(NULL,0,0);
    
    double open1 = iOpen(NULL,0,1);
    double close1 = iClose(NULL,0,1);
    double high1 = iHigh(NULL,0,1);
    double low1 = iLow(NULL,0,1);
    
    double open2 = iOpen(NULL,0,2);
    double close2 = iClose(NULL,0,2);

    double open3 = iOpen(NULL,0,3);
    double close3 = iClose(NULL,0,3);
    
    double open4 = iOpen(NULL,0,4);
    double close4 = iClose(NULL,0,4);
    
    double open5 = iOpen(NULL,0,5);
    double close5 = iClose(NULL,0,5);
    

    
if (
    Ask < iBands(NULL,0,20,2,0,PRICE_MEDIAN,MODE_MAIN,1) &&   // price minore di linea media bollinger
    close5 < open5 &&                                       // down bar 4
    close4 < open4 &&                                       // down bar 3
    close3 < open3 &&                                       // down bar 2
    close2 < open2 &&                                       // down bar 1
    close4 > close3 &&                                      // down trend
    close3 > close2 &&                                      // down trend
    MathAbs(close1 - open1) < VolumeDoji * Point  &&         // DOJI minore di...
    (
        (close1 > open1 && open1 - low1 > OMBRAlow * Point && high1 - close1 < OMBRAhigh * Point && MathAbs(open1 - low1) > MathAbs(close1 - open1)) ||  // Candela verde (up), low grande, high piccolo, ombra piu lunga del corpo
        (close1 < open1 && close1 - low1 > OMBRAlow * Point && high1 - open1 < OMBRAhigh * Point && MathAbs(close1 - low1) > MathAbs(close1 - open1))    // Candela rossa (down), low grande, high piccolo, ombra piu lunga del corpo)    // Candela rossa (down), low grande, high piccolo, ombra piu lunga del corpo
    )
   )
{
    Opn_B = true;
}
 
Federico Libra: Why this happen?

Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
          Code debugging - Developing programs - MetaEditor Help
          Error Handling and Logging in MQL5 - MQL5 Articles (2015)
          Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
          Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)