Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trouble with BackBrushes colors

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

    Trouble with BackBrushes colors

    I'm using the following code to change the background color based on meeting the conditions listed


    PHP Code:
                    Brush shortBrush = new SolidColorBrush(Color.FromArgb(100, 79, 19, 62));
                shortBrush.Freeze();
                Brush longBrush = new SolidColorBrush(Color.FromArgb(100, 22, 64, 24));
                longBrush.Freeze();
    
                if((ema50A[0] < ema50B[0]) && (ema50B[0] < ema200A[0]) && (ema200A[0] < ema200B[0]))
                {
                    //BackBrushes[0] = Brushes.Pink;
                     BackBrushes[0] = shortBrush;
                }
                else if((ema50A[0] > ema50B[0]) && (ema50B[0] > ema200A[0]) && (ema200A[0] > ema200B[0]))
                {
                    //BackBrushes[0] = Brushes.Lime;
                    BackBrushes[0] = longBrush;
                }
    &#8203;
    &#8203; 
    
    When I use the standard brush colors it work fine but is a little more colorful than I want

    Click image for larger version  Name:	image.png Views:	0 Size:	107.2 KB ID:	1262183

    When I use the new RGB brushes, it only pick up the 2nd color

    Click image for larger version  Name:	image.png Views:	0 Size:	111.1 KB ID:	1262184

    what am I doing wrong?​
    Last edited by cre8able; 07-28-2023, 06:55 PM.

    #2
    Oops.

    I was running the brush code in OnBarUpdate and creating a new brush each bar...

    moved to OnStateChange. Can someone confirm thats where is should be?

    thank you​

    Comment


      #3
      Hello cre8able,

      Thanks for your post.

      I understand that you are trying to change the background colors of the chart panel when a certain condition occurs by using BackBrushes.

      To change the background colors of the chart when a certain condition occurs, you could create your conditions in OnBarUpdate() and call BackBrushes[int barsAgo] within the condition in OnBarUpdate().

      If you are referring to using custom brushes to set the background color when calling BackBrushes[int barsAgo], you could create a private class level Brush variable and then instantiate the Brush variable in OnStateChange(). That Brush variable could then be used when setting a value to BackBrushes[int barsAgo].

      For example:

      //class level variables
      private Brush myBrush1;
      private Brush myBrush2;​

      //State.Configure
      myBrush1 = new SolidColorBrush(Color.FromRgb(56, 120, 153));
      myBrush1.Freeze();

      myBrush2 = new SolidColorBrush(Color.FromRgb(99, 10, 55));
      myBrush2.Freeze();​

      //OnBarUpdate()
      if (Close[0] > Open[0])
      BackBrushes[0] = myBrush1;

      if (Close[0] < Open[0])
      BackBrushes[0] = myBrush2;


      See this help guide page for more information about creating custom brushes: https://ninjatrader.com/support/help...gcustombrushes

      See this help guide page for more information about BackBrushes: https://ninjatrader.com/support/help...ackbrushes.htm
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      Comment


        #4
        Thanks Brandon

        when I change to instantiating on state change it worked fine

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        601 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        347 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        559 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        558 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X