Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

PlotBrushes bug or change in 8.1

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

    PlotBrushes bug or change in 8.1

    in the old version a month back I had code that defined a new brush on each new candle, made a color depending on some variable value and then froze the brush and applied it to PlotBrushes[0][0]

    Code:
    Color gradient_1 = pine.color.from_gradient(sosc[0], -100, 100, pine.color.from_brush(DownColor), pine.color.from_brush(UpColor));
    Brush myBrush = new SolidColorBrush(gradient_1);
    myBrush.Freeze();
    PlotBrushes[0][0] = myBrush;​
    color.from_gradient returns a Color object based on the value and min, max,
    color.from_brush returns a Color object from a Brush object

    those are not important as those work as intended still.

    what is important is that this worked in the previous version, but after I manually updated to 8.1 it stopped working

    now it just applies the same color for the whole plot length, and the color used is the first color ever that was applied.

    I've made a little sample to test and it seems when defining a new Brush inside the code, PlotBrushes will always be the first color your custom Brush was.

    Code:
    Brush myBrush = new SolidColorBrush(CurrentBar % 2 == 0 ? Color.FromRgb(255, 0, 0) : Color.FromRgb(0, 255, 0));
    myBrush.Freeze();
    Print(Time[0].ToString() + ": " + myBrush.ToString());
    PlotBrushes[0][0] = myBrush;​
    the code above Prints
    27.3.2023. 15:25:00: #FF00FF00
    27.3.2023. 15:30:00: #FFFF0000
    27.3.2023. 15:35:00: #FF00FF00
    27.3.2023. 15:40:00: #FFFF0000
    27.3.2023. 15:45:00: #FF00FF00
    27.3.2023. 15:50:00: #FFFF0000

    as it should, the Brush object has the correct color inside.

    but the whole plot is just green

    but if I do
    Code:
    PlotBrushes[0][0] = CurrentBar % 2 == 0 ? Brushes.Red : Brushes.Lime;
    then the plot is red and green.

    This has to be a bug, right?​

    I've included an indicator file that has the above-mentioned simplified code and nothing else to showcase that it doesn't work.
    Attached Files

    #2
    Hello LuxSpuzy,

    I am not able to reproduce using the latest release, 8.1.1.2.

    Below is a link to a video of the test.


    I would recommend that you declare the brush variables in the scope of the class, and instantiate them in State.DataLoaded.

    Further, I recommend that the filename, class name, and Name property should always match and be the same to prevent confusion.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I've found the cause of the bug after I saw your post and played around with it a little bit more

      I had a EURUSD 5 Minute chart opened with 365 days worth of data
      the bug starts happening after a certain number of bars have passed
      Click image for larger version  Name:	image.png Views:	0 Size:	71.5 KB ID:	1243035
      and my other indicators only starts plotting after 21 bars have passed, so it's color freeze starts 21 bars later

      also I can't instantiate them in State.DataLoaded because I have a gradient between 2 colors based on a plot value
      so the color keeps changing every candle, I could make 100 brushes and then add them to an array and call them from the array based on the percentage 0-100
      but that seems extreme.
      is there a better way of doing it tho? otherwise I'll have to keep it as is.

      also sorry for any confusion, I did name the .zip file differently
      Last edited by LuxSpuzy; 03-27-2023, 01:52 PM.

      Comment


        #4
        Hello LuxSpuzy,

        You may be hitting the maximum number of brushes allowed.
        https://ninjatrader.com/support/help...gcustombrushes

        Do you seen an error on the Log tab of the Control Center when this occurs?

        Are you able to reproduce the behavior when declaring the brush variables in the scope of the class, and instantiating them in State.DataLoaded as advised in post # 2?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          you are right, I do get the message that there are more than 65535 unique brushes.

          no if I declare them outside it works of course, but like I said, my problem is I need 100 brushes. I guess the only way to do it is to instantiate 100 brushes in DataLoaded, add them to an array, and then fetch them from the array instead of creating a new brush every candle.

          Comment


            #6
            Hello LuxSpuzy,

            Do you need 100 different colors?

            Yes, you would want to instantiate the 100 brushes, likely in a loop, in State.DataLoaded, instead of making thousands of brushes in OnBarUpdate().
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            574 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            332 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            553 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X