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 jxs_xrj, 01-12-2020, 09:49 AM
          5 responses
          3,290 views
          1 like
          Last Post jgualdronc  
          Started by Touch-Ups, Today, 10:36 AM
          0 responses
          6 views
          0 likes
          Last Post Touch-Ups  
          Started by geddyisodin, 04-25-2024, 05:20 AM
          8 responses
          61 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by Option Whisperer, Today, 09:55 AM
          0 responses
          7 views
          0 likes
          Last Post Option Whisperer  
          Started by halgo_boulder, 04-20-2024, 08:44 AM
          2 responses
          24 views
          0 likes
          Last Post halgo_boulder  
          Working...
          X