I have problem to run Logical Operation AND (&&)

 

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

 
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.

 

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
 

Your mistake is

if (SellCondition=true)

should be

if (SellCondition==true)

or just

if (SellCondition)
 
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 

 

Thank you so much!
Reason: