Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using And and Or's

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

    Using And and Or's

    Should something like this work:

    ((A > B && C < D) || (E > F && G < H)) && X > Y && Z > Q

    I had a bit of simple logic performing as desired, based on a string of &&'d statements. But then I added in the bit with the parentheses, and I get compile errors, the editor is looking for a semi colon.

    #2
    coolmoss,

    From what you posted, I can only see one issue :

    ((A > B && C < D) || (E > F && G < H) && X > Y && Z > Q )

    You have an extra parenthesis next to the H and not one at the end next to the Q.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Operator Precedence in Formulas

      I don't see a problem with coolmoss parentheses, as parentheses take presendence in computation over comparison operators.

      Is there any limits for parenthese nesting in NT script?

      This type of conditional statement should also be supported....

      Code:
      (A < B < C)
      Any comments?

      Comment


        #4
        Originally posted by borland View Post
        I don't see a problem with coolmoss parentheses, as parentheses take presendence in computation over comparison operators.

        Is there any limits for parenthese nesting in NT script?

        This type of conditional statement should also be supported....

        Code:
        (A < B < C)
        Any comments?
        code it and find out? would take about 1 minute

        Comment


          #5
          Borland,

          NinjaScript is essentially C# so all code would need to adhere to C# standards.

          Please let me know if I may assist further.
          Adam P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_AdamP View Post
            Borland,

            NinjaScript is essentially C# so all code would need to adhere to C# standards.

            Please let me know if I may assist further.

            To NinjaTrader Service Reps,

            "else if ((Stochastics(7, 14, 3).K[0] < (Stochastics(21, 34, 21).D[0]) && ((CrossBelow(MACD(2, 21, 2), MACD(8, 21, 13).Avg, 1) && ((MACD(2, 21, 2)[1] > MACD(2, 21, 2)[2] && (MACD(2, 21, 2)[1] > MACD(2, 21, 2)[0]) && (MACD(2, 21, 2)[1] > MACD(8, 21, 5)[1] && (MACD(2, 21, 2)[0] <= MACD(8, 21, 5).Avg[0] && ((MACD(2, 21, 2)[3] > MACD(2, 21, 2)[4] && (MACD(2, 21, 2)[3] > MACD(2, 21, 2)[2]) || ((MACD(2, 21, 2)[4] > MACD(2, 21, 2)[5] && (MACD(2, 21, 2)[4] > MACD(2, 21, 2)[3]) && ((MACD(2, 21, 2)[1] < MACD(2, 21, 2)[3]) || (MACD(2, 21, 2)[1] < MACD(2, 21, 2)[4]) && ((ChannelChopCount < 20)))))))))))))))"

            I can't find a general explanation on how to use parentheses in NinjaTrader in any of the help guides I've looked in. If I have just a small logic statement, I can get it to compile and work properly, but if I have a large logic statement like the one above, I can get it to compile without any errors, but I realize that one or more statements are NOT seen by the program. In other words if there are 10 different conditions being tested for, maybe only eight or nine of them will be seen. I'm not sure how to correct this.
            I added " && ChannelChopCount < 20" to the end of logic statement. The above logic statement compiles clean, but the program does NOT see the added statement.
            I thought I understood the syntax, but realize that I really don't. Can someone give me an example showing the proper syntax for the use of the parentheses.

            Thanks in advance for your assistance.
            Last edited by RookieTrader; 07-09-2013, 01:15 PM.

            Comment


              #7
              Hello RookieTrader,

              Thank you for your post.

              Here it is very important to understand the use of the parenthesis and the use of the operators '&&' and '||'.

              If I say I want to check conditionA and conditionB is true or if conditionC is true I use the following:
              Code:
              if((conditionA && conditionB) || conditionC)
              Notice the use of the parenthesis around conditionA and conditionB to ensure these are checked together. Now if I used the following the condition would be different:
              Code:
              if(conditionA && (conditionB || conditionC))
              Now we are checking first if conditionA is true and then if either conditionB or conditionC is true.

              I suggest experimenting with these and building your self up to such a complicated condition as you have listed. It is best to understand how these work and what exactly you are asking in your condition.

              Comment


                #8
                I've reduced some extra ()'s, and tried to line things up to make some sense of your statement.

                ChannelChopCount is nested all the way at the last statement.

                I haven't tested it to verify I didn't screw anything up by removing brackets.
                So it's probably best you take the idea from here, and move things around yourself.


                Code:
                  if (     Stochastics(7, 14, 3).K[0] < Stochastics(21, 34, 21).D[0] 
                     &&  (  CrossBelow(MACD(2, 21, 2), MACD(8, 21, 13).Avg, 1) 
                   && (  MACD(2, 21, 2)[1] > MACD(2, 21, 2)[2] 
                     && (MACD(2, 21, 2)[1] > MACD(2, 21, 2)[0])
                      && (    MACD(2, 21, 2)[1] > MACD(8, 21, 5)[1] 
                       && (   MACD(2, 21, 2)[0] <= MACD(8, 21, 5).Avg[0] 
                       && (    MACD(2, 21, 2)[3] > MACD(2, 21, 2)[4] 
                          && (MACD(2, 21, 2)[3] > MACD(2, 21, 2)[2]) 
                         || (   MACD(2, 21, 2)[4] > MACD(2, 21, 2)[5] 
                          &&  MACD(2, 21, 2)[4] > MACD(2, 21, 2)[3] 
                          && (   MACD(2, 21, 2)[1] < MACD(2, 21, 2)[3]
                             ||  MACD(2, 21, 2)[1] < MACD(2, 21, 2)[4]
                           && ChannelChopCount < 20 
                          )
                          )
                       )
                      )
                     )
                    )
                   ) 
                  )

                I think you wanted it outside, like this:

                Code:
                 if (     Stochastics(7, 14, 3).K[0] < Stochastics(21, 34, 21).D[0] 
                     &&  (  CrossBelow(MACD(2, 21, 2), MACD(8, 21, 13).Avg, 1) 
                   && (  MACD(2, 21, 2)[1] > MACD(2, 21, 2)[2] 
                     && (MACD(2, 21, 2)[1] > MACD(2, 21, 2)[0])
                      && (    MACD(2, 21, 2)[1] > MACD(8, 21, 5)[1] 
                       && (   MACD(2, 21, 2)[0] <= MACD(8, 21, 5).Avg[0] 
                       && (    MACD(2, 21, 2)[3] > MACD(2, 21, 2)[4] 
                          && (MACD(2, 21, 2)[3] > MACD(2, 21, 2)[2]) 
                         || (   MACD(2, 21, 2)[4] > MACD(2, 21, 2)[5] 
                          &&  MACD(2, 21, 2)[4] > MACD(2, 21, 2)[3] 
                          && (   MACD(2, 21, 2)[1] < MACD(2, 21, 2)[3]
                             ||  MACD(2, 21, 2)[1] < MACD(2, 21, 2)[4]
                          )
                          )
                       )
                      )
                     )
                    )
                   ) 
                  && ChannelChopCount < 20   
                  )

                Comment


                  #9
                  Patrick, Sledge,

                  I've been sitting in front of the computer so long my mind starts to play tricks on me. Thanks for the refresher guys. It helped me see where the problem was. After walking through the syntax setup I realize the problem wasn't with the placement of the parentheses. It was a logic problem.

                  Thanks for helping resolve. Have a good night... or a good day depending on when you get this message.

                  Comment


                    #10
                    Patrick, Sledge,

                    I know I'm beating a dead horse, but I realize now that I had way too many parentheses in my logic statements. Corrections would sometimes take hours. I was able too minimize the number of parentheses in my logic statements to a bare minimum. Issues with logic statements now take only seconds to correct. I thought I understood the syntax before, but I realize now that I didn't. I've seen the syntax explained before but it never sunk in. This time it clicked. This has truly made a huge difference.

                    Great appreciation to both of you for your help in clarifying my understanding of this.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    561 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    325 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    101 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    547 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    547 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X