Haha got stumped for a minute or two on this one as well first time needed XOR in MQL.

Just use the not equal Operation: !=

for example if(x != y){...}

x | y | Result |
---|---|---|

false | false | false |

false | true | true |

true | false | true |

true | true | false |

**Michael Kroeker:**

Haha got stumped for a minute or two on this one as well first time needed XOR in MQL.

Just use the not equal Operation: !=

for example if(x != y){...}

The correct answer was given in the post above yours, namely Bitwise Operations! "Not equal to" (!=) is not the same as XOR:

## Bitwise Exclusive Operation OR

The bitwise exclusive OR (eXclusive OR) operation of binary representations of x and y. The value of the expression contains a 1 in all digits where x and y have different binary values, and it contains 0 in all other digits.

b = x ^ y

- docs.mql4.com

**Azael05x:**

I really cant find it in reference... Is there XOR?

xor is if int a,b

xor=(a&&!b)||(!a&&b)

**jack zorlob:**xor=(a&&!b)||(!a&&b)

Don't resurrect old threads without a very good reason.

**William Roeder #:**

No! It is not. That is true only if A and B are both a single bit.

2021.10.12 19:46:41.232 testscr USDSGD,Daily: 1^2=3.00000000

Hi William,

my answer was referring to the bool variables, as seen in the given example. - This is clearly defined by the "NOT"-operator from the (most complex way).

So if this statement is assumed correct, as given by jack zorlob, it must be a boolean interpretation:

xor=(a&&!b)||(!a&&b)

Therefor

XOR = A != B

is right as well, but to speak the same language:

const bool A = false; const bool B = true; const bool x_or = (A != B);

No matter the nature of the inputs, though. They could be anything, but need to be interpreted as boolean variable.

Same accounts for the "original" expression, as the "NOT" operator in use is a logical operator.

Therefor I claim this to be correct statement.

Greetings

https://www.mql5.com/en/docs/basis/operations/bool- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets

You agree to website policy and terms of use