Download MetaTrader 5
To add comments, please log in or register
Deposit to your account via Visa QIWI Wallet
cpr
23
cpr 2016.10.17 22:48 

I have a problem with if condition and && operator.

This simple code alway give "true" as result, when must give "false". Any idea about the problem? I'm getting crazy....

Thanks in advace

double a=3;
   double b=5;
   bool c=true;
   bool d=false;
   
   if ((a<b)&&(c=true)&&(d=true))
   {Alert("TRUE");}
   else
   {Alert("FALSE");}
Blahtech Limited
2831
James Cater 2016.10.17 22:54  
double  a = 3;
double  b = 5;
bool    c = true;
bool    d = false;
   
if (a < b && c && d)
{
   Alert("TRUE");
}
else
{
   Alert("FALSE");
}


In your version you have (d=true) will assign true to d and then always be true

Maybe you meant....

if (a < b && c == true && d == true)
{
}

// but using d == true is not necessary as b is already boolean therefore you should just use

if (a < b && c && d)
{
}
// Also note, there is no need to add loads of extra () surrounding normal conditions unless they contain || expressions that might need to be separated
cpr
23
cpr 2016.10.18 03:52  
jamescater:


In your version you have (d=true) will assign true to d and then always be true

Maybe you meant....


Great! Thanks a lot..it works very good now... but I've got another little problem now... one hour ago it worked well, now it doesn't open any order... I didn't modify the code...

if (Stoc[0])
   {
   OrderSend(Cross,OP_SELL, lots, MarketInfo(Cross,MODE_BID), 1, MarketInfo(Cross,MODE_BID)+(SL*Point), MarketInfo(Cross,MODE_BID)-(TP*Point), "Sell Trade", magic, 0, Red);
   }
   else

if (Stoc[1])
   {
   OrderSend(Cross,OP_BUY, lots, MarketInfo(Cross,MODE_ASK), 1, MarketInfo(Cross,MODE_ASK)-(SL*Point), MarketInfo(Cross,MODE_ASK)+(TP*Point), "Buy Trade", magic, 0, Blue);

   }
else
   {Alert("do nothing");}
/
To add comments, please log in or register