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
    http://msdn.microsoft.com/en-us/library/5011f09h.aspx

    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 Spank, Yesterday, 04:32 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Jason  
      Started by onlinebusiness, Today, 02:31 AM
      0 responses
      11 views
      0 likes
      Last Post onlinebusiness  
      Started by kainermy, Today, 02:08 AM
      0 responses
      10 views
      0 likes
      Last Post kainermy  
      Started by bomberone3, 10-16-2017, 12:16 PM
      11 responses
      2,098 views
      0 likes
      Last Post Spank
      by Spank
       
      Started by BQuinton, Yesterday, 11:06 PM
      0 responses
      38 views
      0 likes
      Last Post BQuinton  
      Working...
      X