conditional operators buggy? (lips>teeth)&&(teeth>jaw) and the seocnd way (lips>teeth>jaw) gave me different results

 

Hallo, I am a newbie so it may be a very stupid question.

I have used the following script

 

//+------------------------------------------------------------------+
//|                                                    alligator.mq4 |
//|                                                            BInko |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "BInko"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
    int numberSymbols = SymbolsTotal(false);
    
      int minBuyShift=10000000;
      string minBuyShiftSymbolName;
      int maxBuyShift=-1;
      string maxBuyShiftSymbolName;
   for(int i = 0; i < numberSymbols; i++){
      string symbolName=SymbolName(i,true);
      int j = 0;
      bool foundAlligatorBuy = false;
      double jaw,teeth,lips;
      while(!foundAlligatorBuy){
         jaw=iAlligator(symbolName,PERIOD_M1,13,8,8,5,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORJAW,j);
         teeth=iAlligator(symbolName,PERIOD_M1,13,8,8,5,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORTEETH,j);
         lips=iAlligator(symbolName,PERIOD_M1,13,8,8,5,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORLIPS,j);
         if((lips>teeth)&&(teeth>jaw)){
            //Alert("Symbol: ", symbolName," Alligator Buy ","Lips:",lips," Teeth: ",teeth," Jaw: ",jaw);
            foundAlligatorBuy =  true;
            break;
         }
         j++;
      }
      if(j<minBuyShift){
         minBuyShift=j;
         minBuyShiftSymbolName = symbolName;
      }
      else if(j>maxBuyShift){
         maxBuyShift=j;
         maxBuyShiftSymbolName = symbolName;
      }
      Alert("Symbol: ", symbolName," Alligator Buy ","Lips:",lips," Teeth: ",teeth," Jaw: ",jaw,"Shift: ",j);
  }
  Alert("Min Buy shift: ",minBuyShiftSymbolName," ",minBuyShift);
  Alert("Max Buy shift: ",maxBuyShiftSymbolName," ",maxBuyShift);
  for(int i = 0; i < numberSymbols; i++){
      string symbolName=SymbolName(i,true);
      double jaw=iAlligator(symbolName,PERIOD_M1,13,8,8,5,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORJAW,0);
      double teeth=iAlligator(symbolName,PERIOD_M1,13,8,8,5,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORTEETH,0);
      double lips=iAlligator(symbolName,PERIOD_M1,13,8,8,5,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORLIPS,0);
      if(jaw>teeth>lips){
        // Alert("Symbol: ", symbolName," Alligator Sell ","Lips:",lips," Teeth: ",teeth," Jaw: ",jaw); 
      }
  }
  }
//+------------------------------------------------------------------+

 

So when I use this conditional operator I get as a result  as of 24.01.2016 01:33 GMT GBPNOK,M1 21:13 22.01.2016 jaws:12,53444 teeth:12.53556, lips:12:53683 j=164

 Which is correct also accorinf to the built-in alligator

But when I use if(lips>teeth>jaw)

I get as a result j=3904 (the large number made me suspicious), lips=29,23737 teeth=29,22346 and jaw=0.0. 

In debugging it just evaluated the condition as false, although it was true, even with the zero value for jaw. then j was 5.

Now I saw that with this condition I also had zero values for lips with other symbols.

 

AS I said I am a newbie here, so have I done something wrong or this operator should not be used.

 

Thank you all for reading my long message 



 
if(lips>teeth>jaw)

I would never write code like this, I would do it as your other method.

I believe that the conditions are tested from left to right.

Firstly

if(lips>teeth)

 is evaluated to true or false. If false it is enumerated as zero. If true, according to the docs it can be enumerated to any other number, but it seems to be always 1.

Then the 2nd part is evaluated, using the value from the first part.

So if the first part is true, the 2nd part will be

if(1>jaw)

 iif the first part is false, the 2nd part will be

if(0>jaw)

 

 I may be wrong

 
Binko_Binev: But when I use if(lips>teeth>jaw)
Exactly. true = 1 and false = 0 so you get
if( 3 < 2 < 1 )
if( false < 1 )
if(     0 < 1 )
if(     true  )
if( 3 > 2 > 1 )
if(  true > 1 )
if(     1 > 1 )
if(     false )
Reason: