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 JoMoon2024, Today, 06:56 AM
        0 responses
        6 views
        0 likes
        Last Post JoMoon2024  
        Started by Haiasi, 04-25-2024, 06:53 PM
        2 responses
        17 views
        0 likes
        Last Post Massinisa  
        Started by Creamers, Today, 05:32 AM
        0 responses
        5 views
        0 likes
        Last Post Creamers  
        Started by Segwin, 05-07-2018, 02:15 PM
        12 responses
        1,786 views
        0 likes
        Last Post Leafcutter  
        Started by poplagelu, Today, 05:00 AM
        0 responses
        3 views
        0 likes
        Last Post poplagelu  
        Working...
        X