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 traderqz, Yesterday, 09:06 AM
          3 responses
          21 views
          0 likes
          Last Post NinjaTrader_ThomasC  
          Started by f.saeidi, Today, 10:19 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by kujista, Today, 06:23 AM
          5 responses
          17 views
          0 likes
          Last Post kujista
          by kujista
           
          Started by traderqz, Today, 12:06 AM
          3 responses
          6 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by RideMe, 04-07-2024, 04:54 PM
          5 responses
          28 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X