Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is it possible to use a Bool with a Condition?

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

    Is it possible to use a Bool with a Condition?

    Hi everyone

    In, for example, the code for the indicator SuperTrend, there's an action which is moderated by a Bool (declared in Variables and confirmed in Properties) as follows:

    Code:
    if (ShowArrows)
    DrawArrowUp(CurrentBar.ToString(), true, 0, UpTrend[0] - TickSize, Color.Blue);
    I'm wondering if it's possible to to do something similar for a condition, along the lines of:

    Code:
    if(
    Condition A
    && if Bool
    Condition B
    )
    Is this possible? If so, what's the appropriate syntax? I've had a few guesses but without any success.

    I'll be much obliged for any help with this.

    #2
    Hello arbuthnot,

    Thanks for your note.

    An if statement with no comparison is the same as comparing the value to true (must be bool).

    So if (ShowArrows) is the same as if (ShowArrows == true).

    You can do the same with your script:

    For example:

    if (ConditionA && ConditionB)
    {
    // execute code
    }

    OR

    if (ConditionA == true && ConditionB == true)
    {
    //execute code
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea

      Thanks very much for your reply and for your very helpful explanation of how " == true" can be elided.

      My apologies - my post wasn't as precise as it should have been!

      What I would like to do is, in the case of two conditions, to be able to moderate one and only one of them using a bool.

      In the generic example I gave...

      Code:
      if(
      Condition A
      && if Bool
      Condition B
      )
      ...I would like Condition B to be moderated by the bool but not Condition A.

      I hope I've made myself clear! If so, maybe you could explain if this is possible, and, if so, how?

      Thanks in advance.

      Comment


        #4
        Hi arbuthnot,

        I'm not entirely clear about what you are asking.

        This is what I have understood. You would like ConditionA to be checked regardless. You would like ConditionB to be checked as long as a bool is set to true.

        This would require nested if statements.

        For example:

        private bool checkB = true;

        if (ConditionA)
        {
        // execute code not dependent on conditionb
        if (checkB == true && ConditionB)
        {
        // execute code dependent on both conditionA and conditionB
        }
        }


        Please let me know if I have understood your question incorrectly.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          That works a treat, Chelsea!

          You certainly understood me perfectly. I've coded as you suggested and - at long last - it compiles. Trouble is, I've still got quite a few lines of code I have to adjust accordingly but I'm sure it will work fine on the chart.

          Thanks very much.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          574 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          333 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          553 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X