Download MetaTrader 5

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

To add comments, please log in or register
MyDream
343
MyDream  

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  
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  

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
Slava
Moderator
6924
Slava  

Your mistake is

if (SellCondition=true)

should be

if (SellCondition==true)

or just

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

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