AND OR handling - page 2

 

if (VariableA == VariableB && VariableC == VariableD > VariableX)
{
bool CriteraMet = true;
}
wrong again

supposed to be

if (VariableA == VariableB && VariableC == VariableD 
    && VariableA > VariableX && VariableB > VariableX && VariableC > VariableX && VariableD > VariableX)
   {
   bool CriteraMet = true;
   }
 

As a programmer of some decades experience, believe me ... simple is best. Do *NOT* try to minimise the number of lines of code.

When you come back to code next year or month (or week or day, even), you can forget what you were doing. Having a long chain of A == B || C == D || E == F can make maintenance difficult when you find a bug, or want an enhancement.

So use separate 'if' statements, unless the criteria are extremely related ( like say EMA5 > EMA9 || EMA7 < EMA11 )

 
Thank you, gjol. Will give it a try and experiment a bit more...
 
brewmanz:

As a programmer of some decades experience, believe me ... simple is best. Do *NOT* try to minimise the number of lines of code.

When you come back to code next year or month (or week or day, even), you can forget what you were doing.

or use self documenting code:
bool macdUp     = ...;
bool maUp       = fastMA > slowMA;
bool openOrders = OrderCount() > 0;
if ((!openOrders && maUP) || macdUP){ // No open orders and uptrend or ..., buy now
Reason: