Announcement

Collapse
No announcement yet.

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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        152 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        89 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        131 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        127 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        107 views
        0 likes
        Last Post CarlTrading  
        Working...
        X