• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8 color to Brush conversion with Opacity

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

    NT8 color to Brush conversion with Opacity

    Hi,

    in NT7 I have

    private Color hldCandleOutlineColour;
    private Color hlCandleOutlineColour;
    private int hlOpacityOL = 120;

    and

    hldCandleOutlineColour = Color.FromArgb(HLOpacityOL , hlCandleOutlineColour);

    which applies an opacity to the color.

    Whats the correct way to do this in NT8? I've seen the solidcolorbrush() example, but that doesn't use opacity and the Brush.Opacity property doesnt seem to exist.

    thanks,
    will.

    #2
    Originally posted by dontpanic View Post
    Hi,

    in NT7 I have

    private Color hldCandleOutlineColour;
    private Color hlCandleOutlineColour;
    private int hlOpacityOL = 120;

    and

    hldCandleOutlineColour = Color.FromArgb(HLOpacityOL , hlCandleOutlineColour);

    which applies an opacity to the color.

    Whats the correct way to do this in NT8? I've seen the solidcolorbrush() example, but that doesn't use opacity and the Brush.Opacity property doesnt seem to exist.

    thanks,
    will.
    Brush has an Opacity property, range 0 to 1.

    ref: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
    https://www.google.com/search?num=10...h.opacity+c%23
    Last edited by koganam; 08-18-2015, 07:06 AM.

    Comment


      #3
      Hello dontpanic,

      As koganam mentioned brushes have an opacity property.

      Try:

      CandleOutlineBrush = Brushes.Blue;
      CandleOutlineBrush.Opacity = 1;
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thanks guys,

        I had actually tried that yesterday and was getting compile errors saying that Opacity wasn't a property, maybe I had brush mixed up with brushes or something, but I was also getting other strange errors trying to use Color.FromArbg() saying that there was no overload for 2 parameters, which is rubbish, so I'm not sure what was going on.

        Anyway, I rewrote all the code as suggested and its compiling ok now, so thanks.

        Will.

        Comment


          #5
          Hello Trader, I also want to use the opacity for the background color but the opacity want not work in my chart version NT8.0.0.7 beta: (no error in the compiler)

          BackBrush = Brushes.Blue;
          BackBrush.Opacity = 0.5;

          thanks for helping.

          Comment


            #6
            Hello schranzi9,

            You are probably getting a run time error that the opacity is read only.

            Try adding the following to OnBarUpdate()

            BackBrush = Brushes.Green;
            Brush newBrush = BackBrush.Clone();
            newBrush.Opacity = 0.25;
            newBrush.Freeze();
            BackBrush = newBrush;
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Does anyone have a solution for this background opacity issue? I've tried the technique listed in this thread, but it's not working. And this appears to be the most recent thread on the subject.

              Any help would be appreciated...I'm not able to change the Opacity of the BackBrush.

              Comment


                #8
                Hello sbgtrading,

                How do you know this is not working?

                Are you getting an error message?

                I have tested this exact code by copying and pasting this into a new indicator in the OnBarUpdate method 'as is'.

                I am not able reproduce an error and I am showing that for each bar, the back color is being changed to have opacity.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  If you are going to frequently change the background color you may run into the dreaded error from creating too many brushes. Best to create your different colored brushes with opacity in State.Configure and then switch between the brushes in OBU.
                  eDanny
                  NinjaTrader Ecosystem Vendor - Integrity Traders

                  Comment


                    #10
                    Hello,

                    eDanny is correct here. The short bit of code I've shared is a quick example of how the back color would be changed.
                    It is best to declare a Brush variable within the scope of the class instead of within the scope of the method so this variable is reused instead of recreated. The creation of too many brushes will result in an error.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Chelsea...it appears to be working now.

                      I had changed the code last week (I'm coloring the background myself in OnRender)...so unfortunately I don't have the exact code I used when I got the error. I think I may have been attempting to change the opacity value of the BackBrush directly, in OnBarUpdate.

                      I've tested it now, using a secondary custom brush, setting its opacity beforehand in the State==Historical block, and then cloning that brush in an assignment to the BackBrush. That's working now.

                      It would be a bit more trouble if I had to set the opacity differently on each background stripe. But then that's what OnRender and RenderTarget.FillRectangle() would be for, I assume.

                      Thanks for your help!

                      Comment


                        #12
                        hi, i want implement in my indicator...


                        else if (State == State.Configure)
                        {
                        alpha = 25 * opacity;

                        BackBrush = Brushes.Green;
                        Brush newBrush = BackBrush.Clone();
                        newBrush.Opacity = alpha;

                        newBrush.Freeze();

                        BackBrush = newBrush;

                        }
                        but in newBrush.Freeze(); i get an error :

                        https://gyazo.com/469df58185139bda346689ad6f781faa

                        Comment


                          #13
                          Hello turbofib,

                          You are attempting to change the color of background of a specific bar before any of the bars have loaded.

                          This is not going to work until there is a bar to change the background color behind in OnBarUpdate.
                          http://ninjatrader.com/support/helpG.../backbrush.htm

                          You may be wanting to set the ChartControl.Properties.ChartBackground.
                          http://ninjatrader.com/support/helpG...properties.htm

                          Wait until DataLoaded before doing this.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            excuse me...
                            I made confusion regarding class BackBrush

                            i want to change opacity of the candle...

                            i've code :

                            else if (State == State.Configure)
                            {
                            alpha = 25 * opacity;

                            newBrush = BarBrush.Clone();
                            newBrush.Opacity = alpha;
                            newBrush.Freeze();

                            }
                            but it give me error because in State.Configure BarBrush....it not exist

                            Can you help me?

                            Comment


                              #15
                              Originally posted by turbofib View Post
                              excuse me...
                              I made confusion regarding class BackBrush

                              i want to change opacity of the candle...

                              i've code :


                              but it give me error because in State.Configure BarBrush....it not exist

                              Can you help me?
                              If you need to do anything to bars, you need to do it after bars have been loaded. The earliest stage at which bars are loaded is State.DataLoaded. Your particular situation should work in that state or any state after that.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by kevinenergy, 10-18-2018, 05:13 PM
                              2 responses
                              36 views
                              0 likes
                              Last Post eDanny
                              by eDanny
                               
                              Started by Trader1001, Today, 12:07 PM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by supermht, 10-20-2018, 10:13 PM
                              2 responses
                              12 views
                              0 likes
                              Last Post NinjaTrader_PatrickG  
                              Started by kevinenergy, Today, 11:53 AM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by verge, Today, 11:36 AM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_PatrickG  
                              Working...
                              X