Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Parenthesis question

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

    Parenthesis question

    Hello,Support!

    Could you please suggest the correct usage of the parenthesis,double (()) or single (),for the || statement?

    Thank you!

    #2
    This is logic101.

    Philosophy Index features an overview of philosophy through the works of great philosophers from throughout time.




    Are you asking is ( a||b||c ) or (( a||b) ||c ) or (a||(b||c)) ? These would result in all the same output.

    if you know C happens 90% of the time, but b&a are the remaining 10%, then you want to go with ( c||b||a )...

    modern compilers use "short circuit evaluation"... so if c is true, there's no need to look at b and a.

    Can you post something concrete?

    This is very generic to any language, and not NT.

    Comment


      #3
      Originally posted by sledge View Post
      This is logic101.

      Philosophy Index features an overview of philosophy through the works of great philosophers from throughout time.




      Are you asking is ( a||b||c ) or (( a||b) ||c ) or (a||(b||c)) ? These would result in all the same output.

      if you know C happens 90% of the time, but b&a are the remaining 10%, then you want to go with ( c||b||a )...

      modern compilers use "short circuit evaluation"... so if c is true, there's no need to look at b and a.

      Can you post something concrete?

      This is very generic to any language, and not NT.
      Hi,sledge,

      No,I don't know which one is more frequent.Two volume bars involved,say bar.a and bar.b.So I want either for the signal, whichever appears first.There are some extra conditions,as well.In the end it's like:

      If(ooohs
      && aaahs
      && jewels
      && cars
      &&(bar.a || bar.b)
      )
      The thing is I was warned one time to be careful using () in the conditions,and provided with the sample with the double(()) surrounded the conditions with the || statement.I actually see no difference.I might be wrong though

      Comment


        #4
        Originally posted by outsource View Post
        Hi,sledge,

        No,I don't know which one is more frequent.Two volume bars involved,say bar.a and bar.b.So I want either for the signal, whichever appears first.There are some extra conditions,as well.In the end it's like:

        If(ooohs
        && aaahs
        && jewels
        && cars
        &&(bar.a || bar.b)
        )
        The thing is I was warned one time to be careful using () in the conditions,and provided with the sample with the double(()) surrounded the conditions with the || statement.I actually see no difference.I might be wrong though
        if none of ooohs/aaahs/jewels/cars is true then (bar.a||bar.b) doesn't matter.


        Code:
        If(ooohs
        && aaahs
        && jewels
        && cars
        &&(bar.a || bar.b)
        )
        if all of ooohs/aaahs/jewels/cars are true -- and bar.a OR bar.b then you are good..

        ----

        now if you said:
        Code:
        If(ooohs
        && aaahs
        && jewels
        && cars
        &&bar.a || bar.b)
        then any of ooohs/aaahs/jewels/cars/bar.a can be false, and if bar.b is true - you are good.




        Well, it's late... so I'm 99.9% sure... best to run a test

        Comment


          #5
          Originally posted by sledge View Post
          if none of ooohs/aaahs/jewels/cars is true then (bar.a||bar.b) doesn't matter.


          Code:
          If(ooohs
          && aaahs
          && jewels
          && cars
          &&(bar.a || bar.b)
          )
          if all of ooohs/aaahs/jewels/cars are true -- and bar.a OR bar.b then you are good..

          ----

          now if you said:
          Code:
          If(ooohs
          && aaahs
          && jewels
          && cars
          &&bar.a || bar.b)
          then any of ooohs/aaahs/jewels/cars/bar.a can be false, and if bar.b is true - you are good.




          Well, it's late... so I'm 99.9% sure... best to run a test
          And what about this?

          If(ooohs
          && aaahs
          && jewels
          && cars
          &&((bar.a || bar.b))
          )

          Comment


            #6
            Originally posted by outsource View Post
            And what about this?

            If(ooohs
            && aaahs
            && jewels
            && cars
            &&((bar.a || bar.b))
            )

            the inner (bar.a || bar.b) goes away... irrelevant...

            at least I hope... haven't tried to defy death like that in many years...

            adding !/~/NOT in front of ( a||b) results in even more fun time... hehe

            Comment


              #7
              Originally posted by outsource View Post
              And what about this?

              If(ooohs
              && aaahs
              && jewels
              && cars
              &&((bar.a || bar.b))
              )
              Redundant brackets. Brackets only need to enclose what is needed to isolate the condition.

              Comment


                #8
                Thanks,sledge and koganam!Thank you guys, I got it.

                Comment


                  #9
                  Originally posted by sledge View Post

                  adding !/~/NOT in front of ( a||b) results in even more fun time... hehe
                  If(ooohs
                  && aaahs
                  && jewels
                  && cars
                  &&(bar.a || bar.b)
                  &&!(zapped == 0)
                  )

                  Really?What happens with the last one then?

                  Comment


                    #10
                    Hello outsource,

                    For this condition to be true:
                    1. aaahs must be true AND
                    2. jewels must be true AND
                    3. cars must be true AND
                    4. bar.a must be true OR bar.b must be true AND
                    5. zapped must NOT EQUAL 0


                    For further information about C# logical operators, please take a look at this link: http://www.tutorialspoint.com/csharp..._operators.htm
                    Zachary G.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_ZacharyG View Post
                      Hello outsource,

                      For this condition to be true:
                      1. aaahs must be true AND
                      2. jewels must be true AND
                      3. cars must be true AND
                      4. bar.a must be true OR bar.b must be true AND
                      5. zapped must NOT EQUAL 0


                      For further information about C# logical operators, please take a look at this link: http://www.tutorialspoint.com/csharp..._operators.htm
                      Hi Zachary,

                      zapped is IntSeries exposed as ''0''.what`s wrong with it?

                      That would be more correct:

                      zapped[0] == 0

                      Comment


                        #12
                        Hello outsource,

                        You have not mentioned that zapped was of type IntSeries.

                        zapped[0] would be correct if you are wanting to get the current value of zapped and compare it to 0.
                        Zachary G.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_ZacharyG View Post
                          Hello outsource,

                          You have not mentioned that zapped was of type IntSeries.

                          zapped[0] would be correct if you are wanting to get the current value of zapped and compare it to 0.
                          Sorry,my bad.

                          so then it will negate the:

                          &&!(zapped[0] == 0)

                          this way,right?

                          Comment


                            #14
                            Hello outsource,

                            The syntax you have provided is comparing zapped[0] (the current value of zapped) to 0.

                            If this is true (zapped[0] == 0), the exclamation point is making it NOT true.

                            So the following statement, !(zapped[0] == 0), will be true if zapped[0] is NOT 0.

                            Example:
                            Code:
                            if (!(zapped[0] == 0))
                                 Print("Hello world!"); // this will only print if zapped[0] is not 0
                            Zachary G.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by outsource View Post
                              Sorry,my bad.

                              so then it will negate the:

                              &&!(zapped[0] == 0)

                              this way,right?
                              While what you have is certainly acceptable to the compiler, I would recommend you use the appropriate relational operator to perform the desired comparison.

                              Why? Because this code,

                              Code:
                              && (zapped[0] != 0)
                              is easier to read than this code,

                              Code:
                              &&!(zapped[0] == 0)
                              See here for some examples:
                              C# - Relational Operators - Following table shows all the relational operators supported by C#. Assume variable A holds 10 and variable B holds 20, then ?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by kujista, Today, 06:23 AM
                              3 responses
                              6 views
                              0 likes
                              Last Post kujista
                              by kujista
                               
                              Started by Mindset, Yesterday, 02:04 AM
                              2 responses
                              17 views
                              0 likes
                              Last Post NinjaTrader_RyanS  
                              Started by f.saeidi, Today, 08:03 AM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by samish18, 04-17-2024, 08:57 AM
                              15 responses
                              52 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by f.saeidi, Today, 08:13 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post f.saeidi  
                              Working...
                              X