Using NULL constant in a condition statement

 
Hi,

I have two trade filter of boolean input variable that I will use in my entry strategy. If the first one is true than use trade filter A and the entry strategy, the code is like this,

void tradeSignal(){
   If(InpUseFilterA)
      If(Filter A && entry long strategy)
         return OPEN_LONG;
   If(InpUseFilterB)
      If(Filter B && entry long strategy)
         return OPEN_LONG;}

I want to simplify the code above to this one,

void tradeSignal(){
   If(InpUseFilterA==true ? UseFilterA : NULL &&
       InpUseFilterB==true ? UseFilterB : NULL &&
       entry long strategy)
         return OPEN_LONG;

Instead of creating new condition for each boolean variable I tried to combine it into one condition, where if InpUseFilterA true than use UseFilterA and if it's false just don't use UseFilterA and moves to the next condition.

I want to ask, 

First, does the simplified version is correct in logic and syntax? And,

Second, is it correct if I using NULL in the condition above?

 
  1.    If(InpUseFilterA==true ? UseFilterA : NULL &&
           InpUseFilterB==true ? UseFilterB : NULL &&

    You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool).

  2. Luandre Ezra: Second, is it correct if I using NULL in the condition above?

    No. NULL is not a boolean. Be careful with NULL.

    1. On MT4, you can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not, OrderSend does not.
    2. Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
    3. Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
    4. MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
      MT5: create them.
    5. Cloud Protector Bug? - MQL4 programming forum (2020)

  3.    bool A = !InpUseFilterA || UseFilterA,
            B = !InpUseFilterB || UseFilterB;
      if( A && B )

 
William Roeder #:
  1. You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool).

  2. No. NULL is not a boolean. Be careful with NULL.

    1. On MT4, you can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not, OrderSend does not.
    2. Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
    3. Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
    4. MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
      MT5: create them.
    5. Cloud Protector Bug? - MQL4 programming forum (2020)


Shouldnt it be:
   bool A = InpUseFilterA && UseFilterA,
        B = InpUseFilterB && UseFilterB;
  if( A || B )
Edit:

The results are the same. No matter which version. Both are correct.

Edit2:

This keeps spinning in my head. The difference between Williams and my version is, mine won't be true, if no filter is selected, contrary to Williams version, which will execute also without an active filter....

 
  1. Dominik Christian Egert #: Shouldnt it be

    No.

    A || B means either filter allows trades. If you enable both, shouldn't both be required to be true in order to trade?

    A && B Means you need both to be true. If you don't to use filter A, you now have FALSE && UseFilterA which is false and no trades.

  2. Dominik Christian Egert #: This keeps spinning in my head. 

    When in doublt create a truth table.

    code  Inp A
     InpB Use A
     Use B
     Trade
    bool A = !InpUseFilterA || UseFilterA,
         B = !InpUseFilterB || UseFilterB;
    if( A && B )
    False
    False
    N/U
    N/U
    Yes (no filter)
    False True N/U B B
    True False A N/U A
    True True
    A B A and B
               
    bool A = InpUseFilterA && UseFilterA,
         B = InpUseFilterB && UseFilterB;
    if( A || B )
    False False N/U N/U  Never
    False
    True
    N/U
    N/U
    Yes (B is true)
    True
    False
    N/U
    N/U
    Yes (A is true)
    True
    False
    N/U
    N/U
    Yes (both true)
 
William Roeder #:

No.

A || B means either filter allows trades. If you enable both, shouldn't both be required to be true in order to trade?

A && B Means you need both to be true. If you don't to use filter A, you now have FALSE && UseFilterA which is false and no trades.

William, what am I not understanding here???

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
    printf("%s", "Williams version:");


    bool A = false;
    bool B = false;

    bool InpUseFilterA  = false;
    bool UseFilterA     = false;
    bool InpUseFilterB  = false;
    bool UseFilterB     = false;


    A = !InpUseFilterA || UseFilterA;
    B = !InpUseFilterB || UseFilterB;

    if( A && B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }



    A = false;
    B = false;
    InpUseFilterA  = true;
    UseFilterA     = false;
    InpUseFilterB  = false;
    UseFilterB     = false;


    A = !InpUseFilterA || UseFilterA;
    B = !InpUseFilterB || UseFilterB;

    if( A && B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }



    A = false;
    B = false;
    InpUseFilterA  = false;
    UseFilterA     = true;
    InpUseFilterB  = false;
    UseFilterB     = false;


    A = !InpUseFilterA || UseFilterA;
    B = !InpUseFilterB || UseFilterB;

    if( A && B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }



    A = false;
    B = false;
    InpUseFilterA  = true;
    UseFilterA     = true;
    InpUseFilterB  = false;
    UseFilterB     = false;


    A = !InpUseFilterA || UseFilterA;
    B = !InpUseFilterB || UseFilterB;

    if( A && B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }


 
    A = false;
    B = false;
    InpUseFilterA  = false;
    UseFilterA     = false;
    InpUseFilterB  = true;
    UseFilterB     = false;


    A = !InpUseFilterA || UseFilterA;
    B = !InpUseFilterB || UseFilterB;

    if( A && B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }


 
    A = false;
    B = false;
    InpUseFilterA  = true;
    UseFilterA     = false;
    InpUseFilterB  = true;
    UseFilterB     = false;


    A = !InpUseFilterA || UseFilterA;
    B = !InpUseFilterB || UseFilterB;

    if( A && B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }


 
    A = false;
    B = false;
    InpUseFilterA  = false;
    UseFilterA     = true;
    InpUseFilterB  = true;
    UseFilterB     = false;


    A = !InpUseFilterA || UseFilterA;
    B = !InpUseFilterB || UseFilterB;

    if( A && B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }


 
    A = false;
    B = false;
    InpUseFilterA  = true;
    UseFilterA     = true;
    InpUseFilterB  = true;
    UseFilterB     = false;


    A = !InpUseFilterA || UseFilterA;
    B = !InpUseFilterB || UseFilterB;

    if( A && B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }


 
    A = false;
    B = false;
    InpUseFilterA  = false;
    UseFilterA     = false;
    InpUseFilterB  = false;
    UseFilterB     = true;


    A = !InpUseFilterA || UseFilterA;
    B = !InpUseFilterB || UseFilterB;

    if( A && B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }



 
    A = false;
    B = false;
    InpUseFilterA  = true;
    UseFilterA     = false;
    InpUseFilterB  = false;
    UseFilterB     = true;


    A = !InpUseFilterA || UseFilterA;
    B = !InpUseFilterB || UseFilterB;

    if( A && B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }



 
    A = false;
    B = false;
    InpUseFilterA  = false;
    UseFilterA     = true;
    InpUseFilterB  = false;
    UseFilterB     = true;


    A = !InpUseFilterA || UseFilterA;
    B = !InpUseFilterB || UseFilterB;

    if( A && B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }



 
    A = false;
    B = false;
    InpUseFilterA  = true;
    UseFilterA     = true;
    InpUseFilterB  = false;
    UseFilterB     = true;


    A = !InpUseFilterA || UseFilterA;
    B = !InpUseFilterB || UseFilterB;

    if( A && B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }



 
    A = false;
    B = false;
    InpUseFilterA  = false;
    UseFilterA     = false;
    InpUseFilterB  = true;
    UseFilterB     = true;


    A = !InpUseFilterA || UseFilterA;
    B = !InpUseFilterB || UseFilterB;

    if( A && B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }



    A = false;
    B = false;
    InpUseFilterA  = true;
    UseFilterA     = false;
    InpUseFilterB  = true;
    UseFilterB     = true;


    A = !InpUseFilterA || UseFilterA;
    B = !InpUseFilterB || UseFilterB;

    if( A && B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }



 
    A = false;
    B = false;
    InpUseFilterA  = false;
    UseFilterA     = true;
    InpUseFilterB  = true;
    UseFilterB     = true;


    A = !InpUseFilterA || UseFilterA;
    B = !InpUseFilterB || UseFilterB;

    if( A && B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }



 
    A = false;
    B = false;
    InpUseFilterA  = true;
    UseFilterA     = true;
    InpUseFilterB  = true;
    UseFilterB     = true;


    A = !InpUseFilterA || UseFilterA;
    B = !InpUseFilterB || UseFilterB;

    if( A && B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A && B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A && B); }









    printf("%s", "\n\nDominiks version:");


    A = false;
    B = false;

    InpUseFilterA  = false;
    UseFilterA     = false;
    InpUseFilterB  = false;
    UseFilterB     = false;


    A = InpUseFilterA && UseFilterA;
    B = InpUseFilterB && UseFilterB;

    if( A || B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }



    A = false;
    B = false;
    InpUseFilterA  = true;
    UseFilterA     = false;
    InpUseFilterB  = false;
    UseFilterB     = false;


    A = InpUseFilterA && UseFilterA;
    B = InpUseFilterB && UseFilterB;

    if( A || B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }



    A = false;
    B = false;
    InpUseFilterA  = false;
    UseFilterA     = true;
    InpUseFilterB  = false;
    UseFilterB     = false;


    A = InpUseFilterA && UseFilterA;
    B = InpUseFilterB && UseFilterB;

    if( A || B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }



    A = false;
    B = false;
    InpUseFilterA  = true;
    UseFilterA     = true;
    InpUseFilterB  = false;
    UseFilterB     = false;


    A = InpUseFilterA && UseFilterA;
    B = InpUseFilterB && UseFilterB;

    if( A || B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }


 
    A = false;
    B = false;
    InpUseFilterA  = false;
    UseFilterA     = false;
    InpUseFilterB  = true;
    UseFilterB     = false;


    A = InpUseFilterA && UseFilterA;
    B = InpUseFilterB && UseFilterB;

    if( A || B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }


 
    A = false;
    B = false;
    InpUseFilterA  = true;
    UseFilterA     = false;
    InpUseFilterB  = true;
    UseFilterB     = false;


    A = InpUseFilterA && UseFilterA;
    B = InpUseFilterB && UseFilterB;

    if( A || B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }


 
    A = false;
    B = false;
    InpUseFilterA  = false;
    UseFilterA     = true;
    InpUseFilterB  = true;
    UseFilterB     = false;


    A = InpUseFilterA && UseFilterA;
    B = InpUseFilterB && UseFilterB;

    if( A || B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }


 
    A = false;
    B = false;
    InpUseFilterA  = true;
    UseFilterA     = true;
    InpUseFilterB  = true;
    UseFilterB     = false;


    A = InpUseFilterA && UseFilterA;
    B = InpUseFilterB && UseFilterB;

    if( A || B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }


 
    A = false;
    B = false;
    InpUseFilterA  = false;
    UseFilterA     = false;
    InpUseFilterB  = false;
    UseFilterB     = true;


    A = InpUseFilterA && UseFilterA;
    B = InpUseFilterB && UseFilterB;

    if( A || B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }



 
    A = false;
    B = false;
    InpUseFilterA  = true;
    UseFilterA     = false;
    InpUseFilterB  = false;
    UseFilterB     = true;


    A = InpUseFilterA && UseFilterA;
    B = InpUseFilterB && UseFilterB;

    if( A || B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }



 
    A = false;
    B = false;
    InpUseFilterA  = false;
    UseFilterA     = true;
    InpUseFilterB  = false;
    UseFilterB     = true;


    A = InpUseFilterA && UseFilterA;
    B = InpUseFilterB && UseFilterB;

    if( A || B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }



 
    A = false;
    B = false;
    InpUseFilterA  = true;
    UseFilterA     = true;
    InpUseFilterB  = false;
    UseFilterB     = true;


    A = InpUseFilterA && UseFilterA;
    B = InpUseFilterB && UseFilterB;

    if( A || B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }



 
    A = false;
    B = false;
    InpUseFilterA  = false;
    UseFilterA     = false;
    InpUseFilterB  = true;
    UseFilterB     = true;


    A = InpUseFilterA && UseFilterA;
    B = InpUseFilterB && UseFilterB;

    if( A || B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }



    A = false;
    B = false;
    InpUseFilterA  = true;
    UseFilterA     = false;
    InpUseFilterB  = true;
    UseFilterB     = true;


    A = InpUseFilterA && UseFilterA;
    B = InpUseFilterB && UseFilterB;

    if( A || B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }



 
    A = false;
    B = false;
    InpUseFilterA  = false;
    UseFilterA     = true;
    InpUseFilterB  = true;
    UseFilterB     = true;


    A = InpUseFilterA && UseFilterA;
    B = InpUseFilterB && UseFilterB;

    if( A || B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }



 
    A = false;
    B = false;
    InpUseFilterA  = true;
    UseFilterA     = true;
    InpUseFilterB  = true;
    UseFilterB     = true;


    A = InpUseFilterA && UseFilterA;
    B = InpUseFilterB && UseFilterB;

    if( A || B )    
    { printf("\nEvaluated True\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }
    else 
    { printf("\nEvaluated False\n InpUseFilterA: %i; UseFilterA: %i => A: %i\n InpUseFilterB: %i; UseFilterB: %i => B: %i\n A || B => %i", InpUseFilterA, UseFilterA, A, InpUseFilterB, UseFilterB, B, A || B); }











    

    return(INIT_FAILED);
}


Sorry for the lengthy code, but thats what we are talking about, isnt it??

 

Lets settle this... it depends on what you want and how you want to apply your filters.


Here are the results of each code version:


Williams version:

Evaluated True
 InpUseFilterA: 0; UseFilterA: 0 => A: 1
 InpUseFilterB: 0; UseFilterB: 0 => B: 1
 A && B => 1

Evaluated True
 InpUseFilterA: 0; UseFilterA: 1 => A: 1
 InpUseFilterB: 0; UseFilterB: 0 => B: 1
 A && B => 1

Evaluated True
 InpUseFilterA: 1; UseFilterA: 1 => A: 1
 InpUseFilterB: 0; UseFilterB: 0 => B: 1
 A && B => 1

Evaluated True
 InpUseFilterA: 0; UseFilterA: 0 => A: 1
 InpUseFilterB: 0; UseFilterB: 1 => B: 1
 A && B => 1

Evaluated True
 InpUseFilterA: 0; UseFilterA: 1 => A: 1
 InpUseFilterB: 0; UseFilterB: 1 => B: 1
 A && B => 1

Evaluated True
 InpUseFilterA: 1; UseFilterA: 1 => A: 1
 InpUseFilterB: 0; UseFilterB: 1 => B: 1
 A && B => 1

Evaluated True
 InpUseFilterA: 0; UseFilterA: 0 => A: 1
 InpUseFilterB: 1; UseFilterB: 1 => B: 1
 A && B => 1

Evaluated True
 InpUseFilterA: 0; UseFilterA: 1 => A: 1
 InpUseFilterB: 1; UseFilterB: 1 => B: 1
 A && B => 1

Evaluated True
 InpUseFilterA: 1; UseFilterA: 1 => A: 1
 InpUseFilterB: 1; UseFilterB: 1 => B: 1
 A && B => 1


Dominiks version:

Evaluated True
 InpUseFilterA: 1; UseFilterA: 1 => A: 1
 InpUseFilterB: 0; UseFilterB: 0 => B: 0
 A || B => 1

Evaluated True
 InpUseFilterA: 1; UseFilterA: 1 => A: 1
 InpUseFilterB: 1; UseFilterB: 0 => B: 0
 A || B => 1

Evaluated True
 InpUseFilterA: 1; UseFilterA: 1 => A: 1
 InpUseFilterB: 0; UseFilterB: 1 => B: 0
 A || B => 1

Evaluated True
 InpUseFilterA: 0; UseFilterA: 0 => A: 0
 InpUseFilterB: 1; UseFilterB: 1 => B: 1
 A || B => 1

Evaluated True
 InpUseFilterA: 1; UseFilterA: 0 => A: 0
 InpUseFilterB: 1; UseFilterB: 1 => B: 1
 A || B => 1

Evaluated True
 InpUseFilterA: 0; UseFilterA: 1 => A: 0
 InpUseFilterB: 1; UseFilterB: 1 => B: 1
 A || B => 1

Evaluated True
 InpUseFilterA: 1; UseFilterA: 1 => A: 1
 InpUseFilterB: 1; UseFilterB: 1 => B: 1
 A || B => 1
 
William Roeder #:
  1. No.

    A || B means either filter allows trades. If you enable both, shouldn't both be required to be true in order to trade?

    A && B Means you need both to be true. If you don't to use filter A, you now have FALSE && UseFilterA which is false and no trades.

  2. When in doublt create a truth table.

    code  Inp A
     InpB Use A
     Use B
     Trade
    False
    False
    N/U
    N/U
    Yes (no filter)
    False True N/U B B
    True False A N/U A
    True True
    A B A and B
               
    False False N/U N/U  Never
    False
    True
    N/U
    N/U
    Yes (B is true)
    True
    False
    N/U
    N/U
    Yes (A is true)
    True
    False
    N/U
    N/U
    Yes (both true)
We are both right.

Look at the OP. You are focusing on the "improved" version, where the condition has changed to "&&" between the two filters, while I am on the original version where there are two "if"-statements, which turns to "||" in the execution path.

So, depending on the source, the outcome is either your, or my version.

That's what kept spinning in my head... There was a change at the source, I didn't grasp at first.



 
Thank you guys for the answer. Gonna try soon.
 

I've check both code and it works find but with a note for Dominik code. If there's 3 filter that I want to use and I want to use 2 out of 3, I think it will become problematic because of how || statement works.

//--- the second example of the brief estimate
   if(!func_false() || !func_true())
     {
      Print("Operation ||: Result of the first expression is true, so the second wasn't calculated");
     }
Since || statement (if it's true) will skip the next code in line, if the first is false and the second it true then even the third condition is true it will be skip. It is not tested but the logic of || statement should be considered if there's more than 2 condition.
 
Luandre Ezra #:

I've check both code and it works find but with a note for Dominik code. If there's 3 filter that I want to use and I want to use 2 out of 3, I think it will become problematic because of how || statement works.

//--- the second example of the brief estimate
   if(!func_false() || !func_true())
     {
      Print("Operation ||: Result of the first expression is true, so the second wasn't calculated");
     }
Since || statement (if it's true) will skip the next code in line, if the first is false and the second it true then even the third condition is true it will be skip. It is not tested but the logic of || statement should be considered if there's more than 2 condition.
That is a general rule of evaluation for boolean operators.

"&&" will continue until it encounters a "false" or reaches the end.

"||" will continue until it encounters a "true" or reaches the end.




 
Luandre Ezra #: I want to use and I want to use 2 out of 3, I think it will become problematic because of how || statement works.
Or (“||”) is irrelevant. You want 2 out of 3, so do 2 out of 3.
bool c1=…, c2=…, c3=…;
if(c1 + c2 + c3 >= 2) Print("2 out of 3"); // False=0 True=1
Reason: