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

Opacity of text color doesnt work

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

    Opacity of text color doesnt work

    I am creating a Draw Text function, but the opacity of it doesnt work in the chart when the text is drawing.
    Could you help me please? Thank you.


    Code:
    Draw.Text(this, "TextTag",
                            true, "Text To Draw",
                            barToDraw, Close[0], 45 ,
                            Brushes.Blue, new NinjaTrader.Gui.Tools.SimpleFont(fontFamily, 10),
                            System.Windows.TextAlignment.Left, null, null, 40 );


    #2
    Hello ninjo,

    Thanks for your post.

    The areaOpacity property for Draw.Text will only set the opacity of the area around the text. If you would like to change the opacity of the brush used to draw the text itself, I recommend creating your own brush and changing the opacity property.

    For example:

    Code:
    protected override void OnBarUpdate()
    {
    [B]    Brush myBrush = new SolidColorBrush(Colors.Blue);
        myBrush.Opacity = 0.5;
        myBrush.Freeze();[/B]
        Draw.Text(this, "TextTag",
                    true, "Text To Draw",
                    0, Close[0], 45 ,
                    myBrush, new NinjaTrader.Gui.Tools.SimpleFont("Arial", 10),
                    System.Windows.TextAlignment.Left, null, null, 40 );        
    }
    Publicly available information on Draw.Text and working with brushes is linked below.

    Draw.Text() - https://ninjatrader.com/support/help...?draw_text.htm

    Working with Brushes - https://ninjatrader.com/support/help...th_brushes.htm

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thank you so much Jim

      Comment


        #4
        How could I change the "Color" property of my declared Brush? (Is not in the NT code list after dot....)


        Thank you

        Comment


          #5
          Hello ninjo,

          The color property would be for a SolidColorBrush, which inherits from System.Windows.Media.Brush.

          Code:
          protected override void OnBarUpdate()
          {
              SolidColorBrush myBrush = new SolidColorBrush(Colors.Blue);
              myBrush.Opacity = 0.5;
              myBrush.Color = Colors.Red;
              myBrush.Freeze();
          
              Draw.Text(this, "TextTag",
                          true, "Text To Draw",
                          0, Close[0], 45 ,
                          myBrush, new NinjaTrader.Gui.Tools.SimpleFont("Arial", 10),
                          System.Windows.TextAlignment.Left, null, null, 40 );        
          }
          Let us know if you have any questions.
          JimNinjaTrader Customer Service

          Comment


            #6
            Hello Jim, thank you, but...


            Setting the opacity of my Brush:

            myBrush.Opacity = 0.5;


            Output window return the next error:

            Error on calling 'OnBarUpdate' method on bar 5455: Cannot set a property on object '#FFFF0000' because it is in a read-only state.


            What I am doing bad?

            Comment


              #7
              Hello ninjo,

              It sounds like you are trying to modify a frozen brush. My recommendation would be to create a brush or brushes in State.DataLoaded, set your desired opacity, freeze the brushes and then use the frozen brushes in your OnBarUpdate code.

              Let us know if we can be of further assistance.
              JimNinjaTrader Customer Service

              Comment


                #8
                Hello Jim,
                That Brush is not frozen. I only change the Opacity.
                My intention is change the opacity in each tick update or when the opacity will changed in the property of the indicator window. Its possible?

                thank you again.
                Last edited by ninjo; 11-29-2018, 04:45 AM.

                Comment


                  #9
                  Hello ninjo,

                  Print(myBrush.IsFrozen); will let you know if the brush is frozen or not. Please be sure to check this if you are getting read only related errors when you are trying to modify your brush.

                  My intention is change the opacity in each tick update or when the opacity will changed in the property of the indicator window. Its possible?
                  You have some options to either create a few brushes and switch through them as you want to change opacity, or you could recreate the brush with the desired opacity set. The example in post #5 will be able to change opacity of the brush on each tick if you use Calculate.OnEachTick and you use a variable or user input for Opacity.

                  If you recreate the brush on each tick, this will have a greater impact on CPU than creating a few brushes in State.DataLoaded and switching between those as needed.

                  Let us know if you have any additional questions.
                  JimNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Perr0Grande, Today, 08:16 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post Perr0Grande  
                  Started by elderan, Today, 08:03 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post elderan
                  by elderan
                   
                  Started by algospoke, Today, 06:40 PM
                  0 responses
                  10 views
                  0 likes
                  Last Post algospoke  
                  Started by maybeimnotrader, Today, 05:46 PM
                  0 responses
                  12 views
                  0 likes
                  Last Post maybeimnotrader  
                  Started by quantismo, Today, 05:13 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post quantismo  
                  Working...
                  X