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

Working around BackBrush.Opacity is in read-only mode

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

    Working around BackBrush.Opacity is in read-only mode

    I have found and read the following post regarding this topic:
    https://ninjatrader.com/support/foru...read-only-mode

    It is not clear to me hot to accomplish setting an opacity value to a background color.

    I am using to UI Properties to obtain the brush color and the opacity value.

    Brush: hTFBullishTrendBackgroundColor

    Opacity as an integer: hTFBullishBackgroundOpacity


    Code:
    if (Closes[1][0] > Closes[1][1])
    
    {
    
    
    
    Brush hTFBullishTrendBackgroundColorCopy = hTFBullishTrendBackgroundColor;
    
    hTFBullishTrendBackgroundColorCopy.Opacity = hTFBullishBackgroundOpacity/100d;
    
    hTFBullishTrendBackgroundColorCopy.Freeze();
    
    BackBrush = hTFBullishTrendBackgroundColorCopy;
    
    }

    I don't want to use SolidColorBrush to define the brush and transparency value as I am getting this information from the user.


    What I am missing? When I ran this code I get the following error:

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

    #2
    Hello GARZONJ,

    You will need to use a SolidColorBrush to define opacity so that part is going to be required, that is needed if you are copying a color so you can access the Color property.

    You also need to create a new brush that is not already created, you can't modify opacity on an existing brush. In what you provided I don't see that part.

    Code:
    SolidColorBrush existingBrush = (SolidColorBrush)UserInputBrushHere; //cast to solidcolor so you can access .Color
    Brush newBackBrush = new SolidColorBrush(existingBrush.Color);  // make a brand new brush using the existing color infomration
    The other post is really the bare minimum at what you would need to copy the existing brush information and make a new brush with an opacity. You can find more information about working with brushes here: https://ninjatrader.com/support/help...gcustombrushes

    If you are taking user input the other post would provide a good structure for taking the color input. You could replace BackBrush in that sample with your user input brush, the null check should not be needed if you are setting a default.
    I look forward to being of further assistance.
    Last edited by NinjaTrader_Jesse; 08-04-2020, 11:43 AM.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by inanazsocial, Today, 01:15 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by rocketman7, Today, 02:12 AM
    0 responses
    10 views
    0 likes
    Last Post rocketman7  
    Started by dustydbayer, Today, 01:59 AM
    0 responses
    1 view
    0 likes
    Last Post dustydbayer  
    Started by trilliantrader, 04-18-2024, 08:16 AM
    5 responses
    23 views
    0 likes
    Last Post trilliantrader  
    Started by Davidtowleii, Today, 12:15 AM
    0 responses
    3 views
    0 likes
    Last Post Davidtowleii  
    Working...
    X