Conditional / Arithmatic Operator

 

Hello MQL Programmer,

my friend shows me some code that i don't really familiar.. here's the chunk of code:

bool foundPosition = TotalOpenPosition != 0;

bool check = foundPosition * (TotalOpenPosition == 0);


Anybody have idea how to intepret/understand this code correctly ?? it's kinda weird for me

 
bool foundPosition;
if (TotalOpenPosition != 0) foundPosition = true;
else foundPosition = false;

bool check;
if (foundPosition && TotalOpenPosition == 0) check = true;
else check = false;

i guess it is.

but the second one is really wierd and i cant see any idea in it. check will always be false

 
could you point me reference for the first statement..
 
veeco:
could you point me reference for the first statement..

didnt get this question... sorry

 
veeco wrote >>
could you point me reference for the first statement..

bool foundPosition = TotalOpenPosition != 0;

Bool can be "true" or "false".

In your Prgramm you have the possibility to set to true or false.

But also you can use the result of something like here....

TotalOpenPositions != 0

!= is for NOT EQUAL or IS NOT

In your case for Example:

if TotalOpenPositions=3 then TotalOpenPositions IS NOT EQUAL to 0 means the result is true (because TotalOpenPositions is not 0) and your foundPosition is set to true

 

Do you know which had more priority to execute, regarding this style code:

int validPosition = tradetimeRange + 60 * TimeFrameMinutes < 0;



Hope there will be type mismatch feature in mq5.. since this style of coding seem "very dirty" to me...

anyone can help me intepret above code ?

 

OMG! Where did you find such a coder :-0 ?


Arithmetical operations have higher priority than logical. So validPosition will be 0 or 1

 

my friend hire a mql coder, and the project didn't finish.. he ask me for a help.. and guess what.. i'm totally confuse about this coding style.. hope fully there will be variable types comparison feature... this style of code is really weird ( but funny... it works though)...


so Garfield, regarding the code above, i believe it could be something like :

if((tradetimeRange+(60*TimeFrameMinutes)<0){

validPosition=1;

}else{

validPosition=0;

}


is that correct ?

 
yeah, its correct