Download MetaTrader 5
To add comments, please log in or register
Do you know that MQL5 has structures?
MyDream
343
MyDream 2012.02.23 15:12 

Hi,

In my EA, I need to do a Logical Operation AND (&&). It give me wrong  result. like:

A=true; B=false;

(A && B) always returns true, it should return false.

Have any body have the same problem? How do you fix it?

Thanks

JDeel
238
JDeel 2012.02.23 19:33  
bool A=true; bool B=false;
if (A && B) {Comment("BOTH TRUE");} else {Comment("A = ",A,"; B = ",B);}

 

This returns "A = true; B = false", as expected. But surely no one can help you if you don't post your code here.

MyDream
343
MyDream 2012.02.24 03:55  

JDeel,

My code is:

bool SellCondition=false;
SellCondition=(m_macd_current<m_macd_previous  &&  m_adxl_main_previous>20);
if (SellCondition=true) {Comment("SellCondition  ",SellCondition, ";   m_macd_current<m_macd_previous",m_macd_current<m_macd_previous, ";        m_adxl_main_previous>20", m_adxl_main_previous>20);
The screen shows: 
SellCondition true; m_macd_current<m_macd_previous  false;   m_adxl_main_previous>20 true
Slawa
Moderator
6830
Slawa 2012.02.24 06:52  

Your mistake is

if (SellCondition=true)

should be

if (SellCondition==true)

or just

if (SellCondition)
Ernie Gunning
1147
Ernie Gunning 2012.02.24 06:53  
MyDream:

JDeel,

My code is:

It seems you have a syntax mistake in your if statement. You should use double equals. You are basically setting it to true and then test if it is true. Which will always be true.

if(SellCondition=true) --- WRONG

if(SellCondition==true) --- right 

MyDream
343
MyDream 2012.02.24 11:45  

Thank you so much!
/
To add comments, please log in or register