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

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(100791962));
                
    shortBrush.Freeze();
                
    Brush longBrush = new SolidColorBrush(Color.FromArgb(100226424));
                
    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
      Brandon H.NinjaTrader Customer Service

      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 BIOK.NT, Today, 01:56 PM
        0 responses
        2 views
        0 likes
        Last Post BIOK.NT
        by BIOK.NT
         
        Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
        11 responses
        37 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by ETFVoyageur, Today, 02:08 AM
        3 responses
        28 views
        0 likes
        Last Post ETFVoyageur  
        Started by Felix Reichert, 04-26-2024, 02:12 PM
        2 responses
        33 views
        0 likes
        Last Post Felix Reichert  
        Started by scalp, Today, 01:26 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Working...
        X