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

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 mattbsea, Today, 05:44 PM
          0 responses
          2 views
          0 likes
          Last Post mattbsea  
          Started by RideMe, 04-07-2024, 04:54 PM
          6 responses
          31 views
          0 likes
          Last Post RideMe
          by RideMe
           
          Started by tkaboris, Today, 05:13 PM
          0 responses
          2 views
          0 likes
          Last Post tkaboris  
          Started by GussJ, 03-04-2020, 03:11 PM
          16 responses
          3,281 views
          0 likes
          Last Post Leafcutter  
          Started by WHICKED, Today, 12:45 PM
          2 responses
          19 views
          0 likes
          Last Post WHICKED
          by WHICKED
           
          Working...
          X