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

Applying Opacity to BackBrush

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

    Applying Opacity to BackBrush

    Dear Support,

    Is there any sample script or reference for applying a predefined opacity level to BackBrush as in the following:

    Code:
    BackBrush = Brushes.Blue;
    Many thanks.

    #2
    Hello aligator,
    Thanks for your post.

    You may change the opacity of BackBrush by creating a custom brush using RGB values to define your color and opacity. For example, the following snippet will create a new custom brush that is lime green, with an opacity of 100.

    Code:
    BackBrush = new SolidColorBrush(Color.FromArgb(100, 50, 205, 50));
    BackBrush.Freeze();
    The opacity value in the Color.FromArgb method goes from 0-255

    I am including a link to the MSDN page on the Color.FromArgb method.
    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    I am also including a link to our help guide below on working with custom brushes.
    https://ninjatrader.com/support/help...gcustombrushes

    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JoshG View Post
      Hello aligator,
      Thanks for your post.

      You may change the opacity of BackBrush by creating a custom brush using RGB values to define your color and opacity. For example, the following snippet will create a new custom brush that is lime green, with an opacity of 100.

      Code:
      BackBrush = new SolidColorBrush(Color.FromArgb(100, 50, 205, 50));
      BackBrush.Freeze();
      The opacity value in the Color.FromArgb method goes from 0-255

      I am including a link to the MSDN page on the Color.FromArgb method.
      https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

      I am also including a link to our help guide below on working with custom brushes.
      https://ninjatrader.com/support/help...gcustombrushes
      Thank you Josh,

      It seem the following modified script without having to use Argb with an Opacity of 0.0 - 1.0 works fine:

      Code:
                      BackBrush  = new SolidColorBrush(Colors.Blue) {Opacity = 0.25};
      However, if I add:

      Code:
                      BackBrush.Freeze();
      the BackBrush will not paint. Do I need to use Freeze() if I just use Colors.Blue instead of rgb?

      All I really care for is having the option to use a variable for opacity.

      Many thanks
      Last edited by aligator; 01-01-2019, 02:43 PM.

      Comment


        #4
        aligator,

        Using .Freeze() works for me on my end no matter if I use Argb values or use your method.

        Anytime you create a custom brush that will be used by NinjaTrader rendering it must be frozen using the .Freeze() method due to the multi-threaded nature of NinjaTrader. If you do not call .Freeze() on a custom defined brush, it will eventually result in threading errors should you try to modify or access that brush after it is defined.

        This is noted along with further information on custom brushes inside of our help guide document regarding how to work with custom brushes: https://ninjatrader.com/support/help...th_brushes.htm

        If you are not seeing the BackBrush color change when you apply your indicator I would check the logs tab for errors. What do you see?



        Josh G.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_JoshG View Post
          aligator,

          Using .Freeze() works for me on my end no matter if I use Argb values or use your method.

          Anytime you create a custom brush that will be used by NinjaTrader rendering it must be frozen using the .Freeze() method due to the multi-threaded nature of NinjaTrader. If you do not call .Freeze() on a custom defined brush, it will eventually result in threading errors should you try to modify or access that brush after it is defined.

          This is noted along with further information on custom brushes inside of our help guide document regarding how to work with custom brushes: https://ninjatrader.com/support/help...th_brushes.htm

          If you are not seeing the BackBrush color change when you apply your indicator I would check the logs tab for errors. What do you see?


          Thanks again Josh,

          First, I apologize. I need BackBrushAll in the above code not BackBrush. But It does not seem to make a difference.

          Second, I am using a logic that will use several brushes for the BackBrushAll depending on the associated if() conditions. Originally, I had placed the Freeze() outside the main condition bracket that would have applied to only one of the sub-conditions inside the bracket. This method did not paint.

          So, I applied the freeze() to all conditional brushes inside the main bracket and it works and paints the BackBurshAll fine.

          However, despite the painting I do get the following error report in the log file.

          "Indicator '': Error on calling 'OnBarUpdate' method on bar 1: Value was either too large or too small for an unsigned byte."

          The indicator seems to paint fine now, but I have no idea what generates this error.

          Many thanks.

          Comment


            #6
            aligator,

            The only time I have seen this error before is when setting a brush with rgb values. Do you get this error each time you apply the indicator or is this perhaps an older error that was still displayed on the log?

            What values are you passing in to your custom brushes?
            Josh G.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_JoshG View Post
              aligator,

              The only time I have seen this error before is when setting a brush with rgb values. Do you get this error each time you apply the indicator or is this perhaps an older error that was still displayed on the log?

              What values are you passing in to your custom brushes?
              No Josh, this was the most recent error. I use a default value of { Opacity = 0.25 } but I have seen Ninja script use { Opacity = .25 f }. However, both of these seem to work fine.

              I pass similar values for 5 different colors using the following format just change to a different default color instead of Blue:
              BackBrushAll = new SolidColorBrush(Colors.Blue) {Opacity = 0.25}; BackBrushAll.Freeze();
              Since the BackBrushAll is based on 5 different conditions on each bar update and only one of them can be true, I was using Freeze() only once outside the bracket containing the 5 conditions. I just applied Freeze() to all 5 conditions and everything seems to be fine now.

              Many thanks for your help and your patience.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by pechtri, 06-22-2023, 02:31 AM
              10 responses
              124 views
              0 likes
              Last Post Leeroy_Jenkins  
              Started by judysamnt7, 03-13-2023, 09:11 AM
              4 responses
              59 views
              0 likes
              Last Post DynamicTest  
              Started by ScottWalsh, Yesterday, 06:52 PM
              4 responses
              36 views
              0 likes
              Last Post ScottWalsh  
              Started by olisav57, Yesterday, 07:39 PM
              0 responses
              7 views
              0 likes
              Last Post olisav57  
              Started by trilliantrader, Yesterday, 03:01 PM
              2 responses
              22 views
              0 likes
              Last Post helpwanted  
              Working...
              X