- A topic for traders.
- select trading time and avoid swap time to trade
- Market etiquette or good manners in a minefield
The
results in true (any value different from 0 is true)
Sorry, but I still don't get it. How can a statement like 8 || 6 == 5 be considered true?
Sorry, but I still don't get it. How can a statement like 8 || 6 == 5 be considered true?
Expression "if (8)" results in true. The "or" part after that is not evaluated when the first part is already true
Ok, the computer basically sees it as 8 is 8, so the first part is true. A bit embarrassing but thanks for the clearing that up!
Ok, the computer basically sees it as 8 is 8, so the first part is true. A bit embarrassing but thanks for the clearing that up!
No, it does not do it that way
Try using 0 instead of 8 and it will become clear what and how it does it
Ok, the computer basically sees it as 8 is 8, so the first part is true. A bit embarrassing but thanks for the clearing that up!
I guess the issue here is operator precedence so I believe you should add parentheses
if ( (1.3898 || 1.4736) == 1.1232)
- False is zero, true non-zero
if(1.3898 || 1.4736 == 1.1232)
if(true || false)
if(true)
- Doubles are rarely equal.
The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum
- False is zero, true non-zero
- Doubles are rarely equal.
The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum
You should familiarize yourself with the concepts of truthy and falsy. All expressions evaluate to a boolean result, and when you have a stand-alone expression like you have - it will still resolve to boolean. In your case
if(1.23456)
is the same as writing
if(1.23456 > 0.0)
Also, an easy way to compare doubles without having to write any extra code is by importing the CDouble library.
#include <Double.mqh> //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { if(Piv1()) Alert("Piv1==true"); } //+------------------------------------------------------------------+ bool Piv1() { if(CDouble::IsEqual(1.4736, 1.1232)) return(true); return(false); } //+------------------------------------------------------------------+
if(1.3898 || 1.4736 == 1.1232) { return(true); } else return(false);Simplify your code.
Increase Order after stoploss - MQL4 and MetaTrader 4 - MQL4 programming forum № 3
if(1.23456)
is the same thing as
if(1.23456!=0)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use