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 MarianApalaghiei, Today, 10:49 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by love2code2trade, Yesterday, 01:45 PM
        4 responses
        28 views
        0 likes
        Last Post love2code2trade  
        Started by funk10101, Today, 09:43 PM
        0 responses
        8 views
        0 likes
        Last Post funk10101  
        Started by pkefal, 04-11-2024, 07:39 AM
        11 responses
        37 views
        0 likes
        Last Post jeronymite  
        Started by bill2023, Yesterday, 08:51 AM
        8 responses
        46 views
        0 likes
        Last Post bill2023  
        Working...
        X