Download MetaTrader 5

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

To add comments, please log in or register
Why to sell products in MetaTrader AppStore? Find that out from the article!
binev_binko 2016.01.24 01:53 

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

I have used the following script


//|                                                    alligator.mq4 |
//|                                                            BInko |
//|                                    |
#property copyright "BInko"
#property link      ""
#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;
            //Alert("Symbol: ", symbolName," Alligator Buy ","Lips:",lips," Teeth: ",teeth," Jaw: ",jaw);
            foundAlligatorBuy =  true;
         minBuyShiftSymbolName = symbolName;
      else if(j>maxBuyShift){
         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);
        // 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 

Keith Watford
Keith Watford 2016.01.24 03:36  

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.



 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


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



 I may be wrong

whroeder1 2016.01.24 12:37  
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 )
To add comments, please log in or register