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 funk10101, Today, 09:43 PM
      0 responses
      6 views
      0 likes
      Last Post funk10101  
      Started by pkefal, 04-11-2024, 07:39 AM
      11 responses
      37 views
      0 likes
      Last Post jeronymite  
      Started by bill2023, Yesterday, 08:51 AM
      8 responses
      44 views
      0 likes
      Last Post bill2023  
      Started by yertle, Today, 08:38 AM
      6 responses
      26 views
      0 likes
      Last Post ryjoga
      by ryjoga
       
      Started by algospoke, Yesterday, 06:40 PM
      2 responses
      24 views
      0 likes
      Last Post algospoke  
      Working...
      X