Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting properties in a class

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

    Setting properties in a class

    I am using a helper class and I set a lot of properties from that class.

    Example :

    Code:
    public class Helper
    {
          public Brush thisBrush = Brushes.Red;
          public SharpDX.Direct2D1.Brush thisBrushDx  = null;
    }
    
    
    In my indicator properties section :
    
    [XmlIgnore]
    public Brush thisBrush
    {
           get { return helper.thisBrush; }
    	set 
    	{ 
    		helper.thisBrush = value;
    				
    		if( helper.thisBrush == null )
    		   return;
    			
    		if( helper.thisBrush.IsFrozen)
    		    helper.thisBrush= helper.thisBrush.Clone();
    				
    		helper.thisBrush.Freeze();
    				
    	  }
    }
    		
    [Browsable(false)]
    public string ThisBrushSerialize
    {
    	get { return Serialize.BrushToString(thisBrush); }
    	set { thisBrush = Serialize.StringToBrush(value); }
    }
    
    public override void OnRenderTargetChanged()
    {
          if(helper.thisBrushDx != null)
            helper.thisBrushDx.Dispose();
    
          if(RenderTarget != null)
          {
                helper.thisBrushDx = helper.thisBrush.ToDxBrush(RenderTarget);
          }
    }
    
    
    And on StateChange
    if(State == State.Terminated)
    {
        if(helper.thisBrushDx != null)
        {
             helper.thisBrushDx.Dispose();
             helper.thisBrushDx = null;
        }
    }

    I am not using State.SetDefaults from OnStateChange() at all to set Brush and SharpDx.Direct2D1.Brush.


    Is that the right pattern to use ?
    Am I wrong in some way ?

    #2
    Hello blar58,

    Thanks for opening the thread.

    As far as I can tell you are serializing the brushes correctly, freezing when you are supposed to and are recreating DxBrushes within the context of OnRenderTargetChanged() as is directed in our help guide.

    As the code is, I get an error when adding the indicator to a chart when I include the helper class. You may wish to use a static class instead to hold a certain data for your Brushes within a helper class.

    Our colleague Jesse has a good sample script that demonstrates using static classes to hold some information external to a NinjaScript. http://ninjatrader.com/support/forum...24&postcount=3

    Best practices for using Brushes and using SharpDx for custom rendering can be referenced below.

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

    Using SharpDx for Custom Rendering - https://ninjatrader.com/support/help..._rendering.htm

    Please let me know if I may be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    72 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    152 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    162 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    100 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    288 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X