whats wrong with MQL4? icustom shows incorrect value

 
below here we can see the last buy position should be opened when there are 3 supertrend in green, the problem is we can see on chart that shift 1 of these 3 supertrend doesnt have all 3 green, one of them is red, down 1.06397, up 1.06185 and up 1.06242, but in journal we see up 1.06127, up 1.06242, up 1.06424, and read the supposedly red one as EMPTY VALUE, what is happening here? why MQL4 read wrong values?


below here is the code..
      bool buy = false, sell = false;
      double b11 = iCustom(Symbol(), PERIOD_CURRENT, INDICATOR_NAME, inp_s1_period, inp_s1_source, inp_s1_atr_mult, inp_s1_atr_mode, 0, 1),
             b12 = iCustom(Symbol(), PERIOD_CURRENT, INDICATOR_NAME, inp_s1_period, inp_s1_source, inp_s1_atr_mult, inp_s1_atr_mode, 0, 2),
             s11 = iCustom(Symbol(), PERIOD_CURRENT, INDICATOR_NAME, inp_s1_period, inp_s1_source, inp_s1_atr_mult, inp_s1_atr_mode, 1, 1),
             s12 = iCustom(Symbol(), PERIOD_CURRENT, INDICATOR_NAME, inp_s1_period, inp_s1_source, inp_s1_atr_mult, inp_s1_atr_mode, 1, 2),
             b21 = iCustom(Symbol(), PERIOD_CURRENT, INDICATOR_NAME, inp_s2_period, inp_s2_source, inp_s2_atr_mult, inp_s2_atr_mode, 0, 1),
             b22 = iCustom(Symbol(), PERIOD_CURRENT, INDICATOR_NAME, inp_s2_period, inp_s2_source, inp_s2_atr_mult, inp_s2_atr_mode, 0, 2),
             s21 = iCustom(Symbol(), PERIOD_CURRENT, INDICATOR_NAME, inp_s2_period, inp_s2_source, inp_s2_atr_mult, inp_s2_atr_mode, 1, 1),
             s22 = iCustom(Symbol(), PERIOD_CURRENT, INDICATOR_NAME, inp_s2_period, inp_s2_source, inp_s2_atr_mult, inp_s2_atr_mode, 1, 2),
             b31 = iCustom(Symbol(), PERIOD_CURRENT, INDICATOR_NAME, inp_s3_period, inp_s3_source, inp_s3_atr_mult, inp_s3_atr_mode, 0, 1),
             b32 = iCustom(Symbol(), PERIOD_CURRENT, INDICATOR_NAME, inp_s3_period, inp_s3_source, inp_s3_atr_mult, inp_s3_atr_mode, 0, 2),
             s31 = iCustom(Symbol(), PERIOD_CURRENT, INDICATOR_NAME, inp_s3_period, inp_s3_source, inp_s3_atr_mult, inp_s3_atr_mode, 1, 1),
             s32 = iCustom(Symbol(), PERIOD_CURRENT, INDICATOR_NAME, inp_s3_period, inp_s3_source, inp_s3_atr_mult, inp_s3_atr_mode, 1, 2);
      buy = valid(b11) && valid(b21) && valid(b31) ? true : false;
      buy = !valid(s11) && !valid(s21) && !valid(s31) ? buy : false;
      buy = valid(s12) || valid(s22) || valid(s32) ? buy : false;
      sell = valid(s11) && valid(s21) && valid(s31) ? true : false;
      sell = !valid(b11) && !valid(b21) && !valid(b31) ? sell : false;
      sell = valid(b12) || valid(b22) || valid(b32) ? sell : false;
      if(buy && !sell && !existTrade(OP_BUY)){
         Print("b1: "+DoubleToStr(b11, Digits));
         Print("b2: "+DoubleToStr(b21, Digits));
         Print("b3: "+DoubleToStr(b31, Digits));
         Print("s1: "+DoubleToStr(s11, Digits));
         Print("s2: "+DoubleToStr(s21, Digits));
         Print("s3: "+DoubleToStr(s31, Digits));
         if(openTrade(OP_BUY)){
            if(existTrade(OP_SELL)) closeTrade(OP_SELL);
            bars = Bars;
         }
      }
      if(sell && !buy && !existTrade(OP_SELL)){
         if(openTrade(OP_SELL)){
            if(existTrade(OP_BUY)) closeTrade(OP_BUY);
            bars = Bars;
         }
      }
i hope someone can help me to figure this out as to why this is happening.. thank you in advance
 
the valid() function is just a simple function to check if the value returned from iCustom is not EMPTY_VALUE and x > 0
 
  1. Your code
          buy = valid(b11) && valid(b21) && valid(b31) ? true : false;
    Simplified
    double buy = valid(b11) && valid(b21) && valid(b31);
              Increase Order after stoploss - MQL4 programming forum #1.3 (2017)
  2. Lutfy Alamsyah: what is happening here? why MQL4 read wrong values?

    How To Ask Questions The Smart Way. (2004)
              Don't rush to claim that you have found a bug.
    Questions Not To Ask
              My program doesn't work. I think system facility X is broken.

    It is almost always your code.

 
William Roeder #:
Your code
Simplified
          Increase Order after stoploss - MQL4 programming forum #1.3 (2017)

thanks for the simplified suggestion, 

and i just figure out that the problem is not from the ea nor the icustom, its from the indicator itself