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

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
    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 :

                        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.


                          You may be wanting to set the ChartControl.Properties.ChartBackground.


                          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 Christopher_R, Today, 12:29 AM
                              0 responses
                              8 views
                              0 likes
                              Last Post Christopher_R  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              166 responses
                              2,235 views
                              0 likes
                              Last Post sidlercom80  
                              Started by thread, Yesterday, 11:58 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post thread
                              by thread
                               
                              Started by jclose, Yesterday, 09:37 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,415 views
                              0 likes
                              Last Post Traderontheroad  
                              Working...
                              X