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

How to use a OR statement in script

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

    How to use a OR statement in script

    Example : close[0] > Open[2] && close[0] >= High[1];

    After or before the " ; " at the end of this statement can I place " OR " and include a different rule/condition

    like this

    close[0] > Open[2] && close[0] >= High[1] OR close[0] > Open[1] && close[0] >= High[1];

    Thanks


    #2
    Originally posted by DTSSTS View Post
    Example : close[0] > Open[2] && close[0] >= High[1];

    After or before the " ; " at the end of this statement can I place " OR " and include a different rule/condition

    like this

    close[0] > Open[2] && close[0] >= High[1] OR close[0] > Open[1] && close[0] >= High[1];

    Thanks
    Not that way. Likely what you are seeking is:
    Code:
    (close[0] > Open[2] && close[0] >= High[1]) || (close[0] > Open[1] && close[0] >= High[1]);
    Pay close attention to your bracketing. It is critical.

    As your AND condition is identical, you can write that more efficiently, to only evaluate the condition if a shorter initial condition fails.
    Code:
    ((close[0] > Open[2]) || (close[0] > Open[1]) && close[0] >= High[1]);
    Or even more concise:
    Code:
    close[0] > Math.Min(Open[2], Open[1]) && close[0] >= High[1];
    Last edited by koganam; 05-05-2019, 05:32 PM.

    Comment


      #3

      (close[0] > Open[2] && close[0] >= High[1]) || (close[0] > Open[1] && close[0] >= High[1]); understand the brackets, like algebra. ^ What key is that above my ^ symbol JUST WANT TO BE SURE IT IS 2 KEY STROKES OF the "SHIFT" OF \ THANKS ALOT

      Comment


        #4
        Originally posted by DTSSTS View Post
        ^ What key is that above my ^ symbol JUST WANT TO BE SURE IT IS 2 KEY STROKES OF the "SHIFT" OF \ THANKS ALOT
        That would depend on what keyboard layout you have. I have function keys above the key "^/6" row, so I am a bit lost on your question. Specifically I have F6 above the ^/6 key.

        Comment


          #5
          THANKS i will test

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Option Whisperer, Today, 09:55 AM
          1 response
          11 views
          0 likes
          Last Post bltdavid  
          Started by port119, Today, 02:43 PM
          0 responses
          1 view
          0 likes
          Last Post port119
          by port119
           
          Started by Philippe56140, Today, 02:35 PM
          0 responses
          2 views
          0 likes
          Last Post Philippe56140  
          Started by 00nevest, Today, 02:27 PM
          0 responses
          1 view
          0 likes
          Last Post 00nevest  
          Started by Jonafare, 12-06-2012, 03:48 PM
          5 responses
          3,986 views
          0 likes
          Last Post rene69851  
          Working...
          X