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 Segwin, 05-07-2018, 02:15 PM
    14 responses
    1,789 views
    0 likes
    Last Post aligator  
    Started by Jimmyk, 01-26-2018, 05:19 AM
    6 responses
    837 views
    0 likes
    Last Post emuns
    by emuns
     
    Started by jxs_xrj, 01-12-2020, 09:49 AM
    6 responses
    3,293 views
    1 like
    Last Post jgualdronc  
    Started by Touch-Ups, Today, 10:36 AM
    0 responses
    13 views
    0 likes
    Last Post Touch-Ups  
    Started by geddyisodin, 04-25-2024, 05:20 AM
    11 responses
    63 views
    0 likes
    Last Post halgo_boulder  
    Working...
    X