• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

what's the best way to multiple if statements

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    what's the best way to multiple if statements

    Hi I'm new to coding.
    If I need multiple if conditions, is it best to separate them by line?
    eg,

    if
    atr >X);
    (any of three indicators > X);
    (any of two indicators > X);
    (any one indicator > X);

    else if
    (atr < X);
    (any of three indicators < X);
    (any of two indicators < X);
    (any one indicator < X);

    or make one quadruple long condition statement
    eg.,
    (any of three indicators > X) || (any of two indicators > X) || (any one indicator > X);

    else if
    (any of three indicators < X) || (any of two indicators < X) || (any one indicator < X);

    #2
    Cowboy, I'm not sure exactly what you're meaning on the first example, the ; terminates the expression. You're essentially still using the same technique of nested if's here with is legal in C#. When you're using using the && or || operators though you want to be aware that C# short circuit evaluates them, meaning as soon as the overall result of the expression is known, no other parts are evaluated (the && operator only evaluates the first Boolean if false, the || operator only evaluates the first Boolean if true).
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Bertrand thanks for the reply.
      Let me try to say this in english as that language I do speak. lol

      I want a code that says if all 3 events happen do this; if 2 of 3 event happen do another thing; and if only 1 of the three events happen do this third thing. This set of if commands are for a bull direction (>).

      Then the same commands would be there only for bear commands <

      I'm not sure how to code this

      Was I able to express this more clearly?

      Thanks

      Comment


        #4
        Originally posted by Cowboy View Post
        Bertrand thanks for the reply.
        Let me try to say this in english as that language I do speak. lol

        I want a code that says if all 3 events happen do this; if 2 of 3 event happen do another thing; and if only 1 of the three events happen do this third thing. This set of if commands are for a bull direction (>).

        Then the same commands would be there only for bear commands <

        I'm not sure how to code this

        Was I able to express this more clearly?

        Thanks
        Just use a counter?
        Code:
        int eventTotal = 0;
        
        if (condition1Happens) eventTotal++;
        if (condition2Happens) eventTotal++;
        if (condition3Happens) eventTotal++;
        
        if (eventTotal == 3) {...}
        else if (eventTotal == 2) {...}
        else if (eventTotal == 1) {...}

        Comment


          #5
          Thanks, I'll try this - coding all new to me - very interesting what can be achieved

          Comment


            #6
            Hello

            Good asking.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by newuser, Today, 08:37 AM
            0 responses
            0 views
            0 likes
            Last Post newuser
            by newuser
             
            Started by bc24fl, Today, 06:51 AM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Jim  
            Started by U0000999, Yesterday, 05:17 AM
            1 response
            15 views
            0 likes
            Last Post NinjaTrader_Kate  
            Started by asmmbillah, Today, 05:03 AM
            2 responses
            22 views
            0 likes
            Last Post asmmbillah  
            Started by lordvader34, Today, 06:18 AM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_PaulH  
            Working...
            X