Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Default brush attributes not being picked up as indicator parameters

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

    Default brush attributes not being picked up as indicator parameters

    So I am porting one of my indicators I call NetLines - below a screengrab from NT7. The Net-Line colors can be set in the indicator settings so in NT8 I'm doing this right now:

    Code:
    [NinjaScriptProperty]
    protected override void OnStateChange()
    		{
    			// properties and indicator settings go here
    			if (State == State.SetDefaults)
    			{
    				......
    				BarCount					= 3;
    				ExpireNL 					= 5;
    				Brush NlblColor			= Brushes.Lime;
    				Brush NlslColor			= Brushes.DarkOrange;
    				Brush OldNlblColor			= Brushes.Teal;
    				Brush OldNlslColor			= Brushes.Red;
    				
    			}
    			// custom resources go here - i.e. indicators, custom data series, bars objects, etc.
    			else if (State == State.Configure)
    			{
    			}
    		}
    
    
    		[Display(ResourceType = typeof(Custom.Resource), Name = "NlblColor", Order = 4, GroupName = "NinjaScriptParameters")]
    		public Brush NlblBrush { get; set; }
    
    		[Browsable(false)]
    		public string NlblBrushSerialize
    		{
    			get { return Serialize.Brush2String(NlblBrush); }
    			set { NlblBrush = Serialize.String2Brush(value); }
    		}
    
                    /// repeated below for the other colors
    Compiles fine but the default colors are not being picked up, so clearly I'm missing something here. Again, this is not a plot color but one used by line draw events. If you look at the indicator it hopefully makes sense.
    Attached Files

    #2
    You have a local Brush declared OnStateChange() scope called NlblColor, however your public property refers to another public NlblBrush. These are different objects and your public brush has nothing assigned. Just make sure to match up the public brush in OnStateChange and it should work as you're expecting.

    Also make sure you have added the XMLIgnore attribute to the public brush

    Code:
    protected override void OnStateChange()
    {
    	if (State == State.SetDefaults)
    	{			
    		Name 			= "MoleCoolor";
    		NlblBrush			= Brushes.Lime;
    	}
    	else if (State == State.Configure)
    	{
    	}
    }
    
    [XmlIgnore]  // make sure to ignore generating xml document field for this property
    [Display(ResourceType = typeof(Custom.Resource), Name = "NlblColor", Order = 4, GroupName = "NinjaScriptParameters")]
    public Brush NlblBrush { get; set; }
    
    [Browsable(false)]
    public string NlblBrushSerialize
    {
    	get { return Serialize.Brush2String(NlblBrush); }
    	set { NlblBrush = Serialize.String2Brush(value); }
    }
    MatthewNinjaTrader Product Management

    Comment


      #3
      Not working... strange...

      Originally posted by NinjaTrader_Matthew View Post
      You have a local Brush declared OnStateChange() scope called NlblColor, however your public property refers to another public NlblBrush. These are different objects and your public brush has nothing assigned. Just make sure to match up the public brush in OnStateChange and it should work as you're expecting.

      Also make sure you have added the XMLIgnore attribute to the public brush

      Code:
      protected override void OnStateChange()
      {
      	if (State == State.SetDefaults)
      	{			
      		Name 			= "MoleCoolor";
      		NlblBrush			= Brushes.Lime;
      	}
      	else if (State == State.Configure)
      	{
      	}
      }
      
      [XmlIgnore]  // make sure to ignore generating xml document field for this property
      [Display(ResourceType = typeof(Custom.Resource), Name = "NlblColor", Order = 4, GroupName = "NinjaScriptParameters")]
      public Brush NlblBrush { get; set; }
      
      [Browsable(false)]
      public string NlblBrushSerialize
      {
      	get { return Serialize.Brush2String(NlblBrush); }
      	set { NlblBrush = Serialize.String2Brush(value); }
      }

      Well, that's embarrassing!

      BTW, why do I need those [XmlIgnore] attributes? I do want those colors to show and be selectable/changeable in the indicator's parameters.

      Anyway, I made the change and would love to tell you that it's now working but it's not :-(

      I'll email you the stub code - perhaps you can pull it up and try it.

      Comment


        #4
        I responded to your code, let me know if that doesn't help or you have questions.

        XmlIgnore-> the brush object itself cannot be saved to the xml (workspace) file. So you add that attribute which tells the XmlSerializer routine to skip that field.

        This is also why you have to add that string brush object-> that string is what is actually being saved to the workspace xml file and allows you to restore any user defined colors which might deviate from the default value.
        MatthewNinjaTrader Product Management

        Comment


          #5
          Originally posted by NinjaTrader_Matthew View Post
          I responded to your code, let me know if that doesn't help or you have questions.

          XmlIgnore-> the brush object itself cannot be saved to the xml (workspace) file. So you add that attribute which tells the XmlSerializer routine to skip that field.

          This is also why you have to add that string brush object-> that string is what is actually being saved to the workspace xml file and allows you to restore any user defined colors which might deviate from the default value.
          Yeah, you nailed it - sorry again for bothering you with something so trivial. I guess I'm just not used to defining my properties 4.x style. Thanks again.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Segwin, 05-07-2018, 02:15 PM
          10 responses
          1,767 views
          0 likes
          Last Post Leafcutter  
          Started by Rapine Heihei, 04-23-2024, 07:51 PM
          2 responses
          30 views
          0 likes
          Last Post Max238
          by Max238
           
          Started by Shansen, 08-30-2019, 10:18 PM
          24 responses
          943 views
          0 likes
          Last Post spwizard  
          Started by Max238, Today, 01:28 AM
          0 responses
          9 views
          0 likes
          Last Post Max238
          by Max238
           
          Started by rocketman7, Today, 01:00 AM
          0 responses
          7 views
          0 likes
          Last Post rocketman7  
          Working...
          X