Mixing Strings and Doubles in IF statement

 

Consider the following:

double  Main_0;

string Trend;

..(bit of calculation here)

if (Trend="UP" && Main_0 >40 )

{

Do something

}


I don't see why I should get "implicit conversion from number to string" error in the IF statement. If I remove either Trend or Main_0 it compiles OK.

-Jerry

Documentation on MQL5: Conversion Functions / DoubleToString
  • www.mql5.com
Conversion Functions / DoubleToString - Documentation on MQL5
 
netconuk posted # :

Consider the following:

Because your code has a single =, it is combining string && bool

You need to use

if (Trend=="UP" && Main_0 >40 )

Paul

/go?link=http://paulsfxrandomwalk.blogspot.com/ 

 
phampton:
netconuk posted # :

Consider the following:

Because your code has a single =, it is combining string && bool

You need to use

if (Trend=="UP" && Main_0 >40 )

Paul

/go?link=http://paulsfxrandomwalk.blogspot.com/ 

AHHH! Of course. Many thanks Paul.

In MT4 it would warn you of creating an assignment within an IF block. Is this something that needs fixing in MT5?

-Jerry

 
netconuk posted # :

AHHH! Of course. Many thanks Paul.

In MT4 it would warn you of creating an assignment within an IF block. Is this something that needs fixing in MT5?

-Jerry

Believe me, I've done it many times myself.  I thought about the warning too - it's not entirely simple because your earlier code is legal C, so the warning would pop up in a rather irritating fashion every time you compile even for intentional instances.  Microsoft Visual C++ does give a warning, but once that module is compiled and is left unchanged then you don't see the warning again unless you rebuild the entire project. 

 Paul

/go?link=http://paulsfxrandomwalk.blogspot.com/ 

Reason: