Download MetaTrader 5

Mixing Strings and Doubles in IF statement

To add comments, please log in or register
Deposit to your account via Visa QIWI Wallet
Jerry Spence
216
Jerry Spence 2010.02.23 01:35 

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
Paul
784
Paul 2010.02.23 03:09  
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

http://paulsfxrandomwalk.blogspot.com/ 

Jerry Spence
216
Jerry Spence 2010.02.23 10:37  
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

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

Paul
784
Paul 2010.02.23 12:47  
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

http://paulsfxrandomwalk.blogspot.com/ 

To add comments, please log in or register