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 - Custom Brushes color from Argb

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

    NT8 - Custom Brushes color from Argb

    Hi - I've searched and not found; could you help?
    I'd like to create a custom Argb color for my private Brushes.
    What works for "standard" colored private Brushes:
    // within: if (State == State.SetDefaults)
    UpGreen = Brushes.DarkGreen;
    // then within #region Properties
    [NinjaScriptProperty]
    [XmlIgnore]
    [Display(Name="UpGreen", Order=8, GroupName="Parameters")]
    public Brush UpGreen
    { get; set; }

    [Browsable(false)]
    public string UpGreenSerializable
    {
    get { return Serialize.BrushToString(UpGreen); }
    set { UpGreen = Serialize.StringToBrush(value); }
    }
    ---------------------------------------------
    Now my challenge, how to customize the Brushes color with Argb. I expected this to work:
    "UpGreen = Brushes.(Brushes.FromArgb(50,0,80,40));"
    But it does not work. Thanks in advance.

    #2
    Hello JulieC,

    The Color.FromArgb() is used when creating a color in code.


    If you are wanting to be able to type an argb or hex value, you can do this with a normal brush. No fancy code required.
    Below is a link to the help guide on Using Color Pickers. Please see the section 'Using Custom Colors'.


    And a link to tips post about serializing a brush.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks ChelsaeB,
      Success!! The code I used that allows a custom Brush for user definable Brushes:
      // within OnStateChange()
      UpGreen = new SolidColorBrush(Color.FromArgb(255, 0,70,30));
      // then further detailed in Properties as described in identified post 416543
      ------------------------------------------------------------------
      A follow-up question if i may:
      Regarding "Order=0" within the Properties section... In comparing the code from post 416543 and the code generated by the Wizard, i find these variations:
      From Wizard -
      [Display(Name="UpGreen", Order=8, GroupName="Parameters")]
      From post 416543
      [Display(Name="UpGreen", GroupName="NinjaScriptParameters", Order=0)]
      History: in creating an indicator with the Wizard i wanted code generated for all possible user definable inputs, so a asked for a couple of each -- double, int, bool, Brushes, time -- and thereby created examples of each type for study. In doing so the quantity grew to Order=9.
      Subsequently, not needing all the user definable inputs, i have commented out most.
      QUESTION:
      What are the requirements regarding "Order=?"
      Must the items begin with 0? (my "0" is currently commented out)
      Must they be sequential?
      Must the code be arranged line-by-line in "Order=?" numerical sequence?
      Must there be no omissions in sequence?

      -----------------------------------
      Using Color Pickers is slick!!
      I initially entered quotation marks along with the RGB - Wrong!
      Just type away.....my example..... 0,70,30
      Thanks for that.

      Comment


        #4
        JulieC,

        The Order property in the Display attribute is not picky.

        It doesn't have to start at 0.
        The Order values used do not have to be sequential.
        There can be omissions in the sequence.
        If two items have the same order they will sort alphabetically.

        Are you testing using these and having an unexpected behavior?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Yes I am having unexpected behavior – the indicator fails. However, I am not sure what the cause is or if the cause is linked to “Order=?”. It is a strong possibility.
          I’ve disabled all user defined inputs and the indicator works.
          Two errors are logged:

          Unhandled exception: Write lock may not be acquired with read lock held. This pattern is prone to deadlocks. Please ensure that read locks are released before taking a write lock. If an upgrade is necessary, use an upgrade lock in place of the read lock.

          Unhandled exception: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

          What do you suggest ChelseaB? What am i missing? Is my error related to recent work?
          Thanks

          Comment


            #6
            This is occurring because you have not frozen the brush before attempting to use it. Here is an excerpt from the help guide that goes into more detail.

            Originally posted by http://ninjatrader.com/support/helpGuides/nt8/en-us/working_with_brushes.htm




            // initiate new solid color brush which has an alpha (transparency) value of 100
            MyBrush = new SolidColorBrush(Color.FromArgb(100, 56, 120, 153));
            myBrush.Freeze();

            Draw.Line(this, "tag1", true, 10, 1000, 0, 1001, myBrush, DashStyleHelper.Dot, 2);





            Warning: If you do not call .Freeze() on a custom defined brush WILL eventually result in threading errors should you try to modify or access that brush after it is defined
            Jessica P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by The_Sec, Yesterday, 03:37 PM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by vecnopus, Today, 06:15 AM
            0 responses
            1 view
            0 likes
            Last Post vecnopus  
            Started by Aviram Y, Today, 05:29 AM
            0 responses
            5 views
            0 likes
            Last Post Aviram Y  
            Started by quantismo, 04-17-2024, 05:13 PM
            3 responses
            27 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by ScottWalsh, 04-16-2024, 04:29 PM
            7 responses
            36 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X