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

Shoud I freeze custom color brush, created inside Draw.Region()

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

    Shoud I freeze custom color brush, created inside Draw.Region()

    Hello.
    If I creating region with custom color area:

    Code:
    var mr = Draw.Region(this, "my_region", 0, 0, Plot_X, Plot_Y,   null, new SolidColorBrush( WmColor.FromArgb( 100, 050, 100, 200 )), 3 );
    Should I freeze brush at once?

    If I should, can I do it this way:
    Code:
    mr.AreaBrush.Freeze();
    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    #2
    Hello fx.practic,

    Yes, you should call .Freeze() on a custom defined brush.

    I would suggest seeing the following section of our helpguide under Understanding Custom Brushes.



    Per the helpguide, you should create a new brush object, initiate it, freeze it, then pass it to your Draw.Region method.

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      That's clear, thank You.

      And what about this way?

      Code:
      Brush Color_To_Brush( Color color )
      {
         Brush brush = new SolidColorBrush( color );
         brush.Freeze();
         return brush;
      }
      
      var mr = Draw.Region(this, "my_region", 0, 0, Plot_X, Plot_Y,   null, Color_To_Brush( Color.FromArgb( 100, 050, 100, 200 )), 3 );
      fx.practic
      NinjaTrader Ecosystem Vendor - fx.practic

      Comment


        #4
        And what about this way?

        Code:
        List<Brushes> All_Brushes = new List<Brushes>();
        
        Brush Color_To_Brush( Color color )
        { 
           All_Brushes.Add(  new SolidColorBrush( color ) );
           All_Brushes.Last().Freeze();
           return All_Brushes.Last();
        }
        
        var mr = Draw.Region(this, "my_region", 0, 0, Plot_X, Plot_Y,   null, Color_To_Brush( Color.FromArgb( 100, 050, 100, 200 )), 3 );
        
        protected override void OnStateChange()
        {
           if (State == State.Terminated) 
           {	
                foreach( Brush brush in All_Brushes )
                       if( brush != null ) brush.Dispose();
           }
        }
        fx.practic
        NinjaTrader Ecosystem Vendor - fx.practic

        Comment


          #5
          Hello fx.practic,

          I would suggest seeing the following two references examples which demonstrate freezing a brush. See attached.

          Please let us know if you need further assistance.
          Attached Files
          Alan P.NinjaTrader Customer Service

          Comment


            #6
            Thank You for examples.

            But, I don't see explicit calling of <Brush>.Dispose() method for each brush.

            Manual says:

            Warning: Any SharpDX Brush object used in your development must be disposed of after they have been used. NinjaTrader is NOT guaranteed to dispose of these resources for you! Please see the Best Practices for SharpDX Resources section on this page for more information.
            Does it concern to DxBrushes only?

            Does each Windows.Media.Brush need to be disposed separately and explicitly, or it doesn't?
            fx.practic
            NinjaTrader Ecosystem Vendor - fx.practic

            Comment


              #7
              Originally posted by NinjaTrader_AlanP View Post
              Hello fx.practic,

              I would suggest seeing the following two references examples which demonstrate freezing a brush. See attached.

              Please let us know if you need further assistance.
              Hi AlanP,

              Your aRender.sc gives an excellent example for gradient rendering of custom shapes such as a rectangle or an ellipse. The rendering require coding the dimensions for the shape fill area.

              However, for custom LinearGradient rendering of candle sticks bars the dimensions for the candlesticks are already defined by the chart type.

              In a sample case, I want to paint bars using a linear gradient brush in red or green depending on an oscillator is below or above the zero line, respectively. Or, a single bar such as an engulfing bar. In such a case, how a candle(s) is rendered in linear gradient color without having to define the dimension of the fill area? A code snippet to show how this task is handled is appreciated.

              A simple example is rendering an Inside Bar candle with a LinearGradient brush.

              Many thanks.

              Comment


                #8
                This approach works norm. It can be checked by <Brush>.IsFrosen


                PHP Code:
                Brush Color_To_BrushColor color )
                {
                   
                Brush brush = new SolidColorBrushcolor );
                   
                brush.Freeze();
                   return 
                brush;
                }

                Region my_region Draw.Region(this"my_region"00Plot_XPlot_Y,   nullColor_To_BrushColor.FromArgb100050100200 )), );

                Print( 
                my_region.AreaBrush.IsFrozen ); 


                Here some related info from MSDN: Freezable Objects Overview

                It have sense for my in indicators with 20+ different colors. It let me use less code.
                Also, some colors components manipulation can be done in function.
                Last edited by fx.practic; 08-02-2017, 02:16 AM.
                fx.practic
                NinjaTrader Ecosystem Vendor - fx.practic

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by usazencort, Today, 01:16 AM
                0 responses
                1 view
                0 likes
                Last Post usazencort  
                Started by kaywai, 09-01-2023, 08:44 PM
                5 responses
                603 views
                0 likes
                Last Post NinjaTrader_Jason  
                Started by xiinteractive, 04-09-2024, 08:08 AM
                6 responses
                22 views
                0 likes
                Last Post xiinteractive  
                Started by Pattontje, Yesterday, 02:10 PM
                2 responses
                21 views
                0 likes
                Last Post Pattontje  
                Started by flybuzz, 04-21-2024, 04:07 PM
                17 responses
                230 views
                0 likes
                Last Post TradingLoss  
                Working...
                X