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

Conditional statements

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

    Conditional statements

    This should be basic but cannot think straight, therefore need some help perhaps with the nesting of the conditional statements.
    For instance:

    if ( A && B && C) {
    BarColor }

    But after the initial statement, I would like BarColor to continue even if one of the conditions remains true. Thanks in advance...

    #2
    Hello 2Look4me,

    Thank you for your post.

    Set up a Color variable and set it outside your condition, but set the color to be used when your condition is true. For example:
    Code:
            #region Variables
    		private Color myColor = Color.Red;
            #endregion
    
            protected override void Initialize()
            {
    			
            }
    
            protected override void OnBarUpdate()
            {
    			if(myCondition) // myCondition is just a placeholder for your actual condition
    			{
    				myColor = Color.Blue;
    			}
    			
    			BarColor = myColor;
            }
    This will initially set the 'myColor' to Red, so the bar's are red until my condition is true - in which case the bars are now Blue.

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

    Comment


      #3
      PatrickH, thanks for the fast response.

      Using your example:
      Code:
      if (A && B && C)
        {
                    myColor=Color.Blue;
        }
        BarColor  = myColor;
      I will have Blue bars when the conditions A, B and C are all true.
      But after my initial conditional statement (A && B && C), if A is no longer true, I would still want the bar colored Blue and if neither A nor B are true, but C is, I would still want the bar colored Blue. So if A, B and C are no longer true, the bars will be Red.

      Therefore my problem is with the subsequent conditional statements . Thanks again.

      Comment


        #4
        Hello 2Look4me,

        Thank you for your response.

        You would only need one more condition:
        Code:
        if(!A && !B && !C)
        {
        myColor = Color.Red;
        }

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,607 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        9 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        19 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        6 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        15 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X