Possible conditional check error - page 6

 
amrali:

As I said before, this simple loop became so unreadable. You sacrifice readability for a neglible gain in performance. It deos NOT worth it.

A simple if..else statement plus compiler optimizations and hardware branch predictors wins at the end.

At least an order of magnitude (10x) gain in performance is considered good.

I know Amrali, it's just for fun.

 
Alain Verleyen:

I know Amrali, it's just for fun.

I enjoyed it. Thanks Alain 
 

Hi!

Also me compilator returns a warning "result of expression not used" but why??

I'd like to gererate a random trade... 🙏

MathRand() < 16384 ? buy(0.01, Ask, magicNr, comment, _Symbol) : sell(0.01, Bid, magicNr, comment, _Symbol);
 
Milko Vivaldi #: Also me compilator returns a warning "result of expression not used" but why??

Buy() and sell() return a value. The statement ignores the result. Equivalent to:

if(MathRand() < 16384){
  /*expression should be checked*/  buy(0.01, Ask, magicNr, comment, _Symbol);
}else{
  /*expression should be checked*/ sell(0.01, Bid, magicNr, comment, _Symbol);
}
 
William Roeder #:

Buy() and sell() return a value. The statement ignores the result. Equivalent to:

Yes, I've done in this way (with if) but I can't understand why ternary operator doesn't accept 0 or 1 as result i.e. true or false... because my buy and sell functions are bool functions therefore return true or false

 
Milko Vivaldi #: Yes, I've done in this way (with if) but I can't understand why ternary operator doesn't accept 0 or 1 as result i.e. true or false... because my buy and sell functions are bool functions therefore return true or false

Ternary results in either. “Both functions return a bool”. The result you ignore the result, thus the error.