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

Boolean within a set of conditions

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

    Boolean within a set of conditions

    Hi everyone

    I've declared a boolean (in Variables and Properties) - let's called it BoolA - and I'd like to use it within a set of conditions so that after an '&&', I can state the boolean to select whether the condition applies.

    I've tried this but it doesn't compile:

    Code:
    if([I]conditions..[/I].
    
      && (BoolA) ( [I]condition[/I]... )
    
    )
    I'd appreciate a pointer as to how to get this coding to work.

    Many thanks in advance.
    Last edited by arbuthnot; 05-08-2014, 02:58 PM. Reason: Correcting title

    #2
    Hello arbuthnot,

    Let me check if I have understood your question correctly. You have an if statement and you would like to check if a Boolean is true or false. Depending on the outcome of the Boolean you would want the if statement to execute or not kind of like a toggle switch, is this correct?

    If this is the case you could do something like the following
    Code:
    if(condition1 && boolA)
    {
    }
    If that is not what you wanted you could also do a nested if statement like below
    Code:
    if(conditions)
    {
    if(boolA)
    {
    // if boolA is true
    } else {
    // if boolA is false
    }
    // more code here
    }
    Rather than doing an && checking if condition 1 AND condition 2 are met, nesting provides a similar effect. the above example would read if conditions are met then move on to the inner if statement, The inner if statement checks if boolA is true and if so executes the code, otherwise it will do the second half of the if statement after the "else" when it is false;

    Also here is a great resource on If statement usage from MSDN
    The `if` and `switch` statements provide branching logic in C#. You use `if, `else` and `switch` to choose the path your program follows.


    Please let me know if I may be of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks very much, Jesse, for this advice and the link, which is very helpful.

      I'll try to apply your tips and if I have any further problems, I'll come back to you.

      Cheers.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by rocketman7, Today, 02:12 AM
      3 responses
      20 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by trilliantrader, 04-18-2024, 08:16 AM
      7 responses
      27 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by samish18, 04-17-2024, 08:57 AM
      17 responses
      65 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by briansaul, Today, 05:31 AM
      1 response
      13 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by PaulMohn, Today, 03:49 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X