• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exposing Pens as properties ?

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

    Exposing Pens as properties ?

    Hi,

    I saw in the VolumeProfile indy that you enabled the exposure of Brushes as properties to allow Color choosing.

    I tried to expose a Pen, so there is also thickness and dash style to choose from, like you have for Plots and Lines, but it doesn't work in the indicator property grid (empty field)

    The serialization code is built, though, because
    Code:
            [XmlIgnore]
            [Display(ResourceType = typeof(Custom.Resource), Name = "VolumeNeutralColor", Order = 4, GroupName = "NinjaScriptParameters")]
            public Pen VolumeNeutralPen { get; set; }
    
            [Browsable(false)]
            public string VolumeNeutralPenSerialize
            {
                get { return Serialize.Pen2String(VolumeNeutralPen); }
                set { VolumeNeutralPen = Serialize.String2Pen(value); }
            }
    works, but no Pen chooser appears in the property grid.


    Any way to make it work ?

    Thanks

    #2
    The property grid was not designed to display Pens. You can used a Stroke instead which has Brush, Dash Style and Width properties.

    In fact, it is worth mentioning that in Beta 3, the concept of Pens for Plots and other coloring has been removed for simplicity, as any use case that would use a pen can be used by a Stroke. Stroke does not need to be Frozen, and there is no special handling you need to do to serialize a Stroke

    Code:
    [Display(ResourceType = typeof(Custom.Resource), Name = "MyStroke", Order = 4, GroupName = "NinjaScriptParameters")]
    public Stroke MyStroke { get; set; }
    
    protected override void OnStateChange()
    {		 
    	if (State == State.SetDefaults)
    	{											
    		MyStroke = new Stroke(Brushes.Blue, 2);
    	}			
    }
    Last edited by NinjaTrader_Matthew; 06-24-2015, 06:28 AM.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Any clever way to simply get a SharpDX brush with the Stoke color?

      I tried
      SharpDX.Direct2D1.Brush brush=outlineStroke.BrushDX;
      but it crashed Ninja

      So I use

      Color color=((SolidColorBrush)outlineStroke.Brush).Color ;
      using (SharpDX.Direct2D1.SolidColorBrush brush = new SharpDX.Direct2D1.SolidColorBrush(graphics,new SharpDX.Color4((float)color.R/255.0f,(float)color.G/255.0f, (float)color.B/255.0f,(float)color.A/255.0f)))

      but feels kind of clumsy...

      Comment


        #4
        Originally posted by NinjaTrader_Matthew View Post
        The property grid was not designed to display Pens. You can used a Stroke instead which has Brush, Dash Style and Width properties.

        In fact, it is worth mentioning that in Beta 3, the concept of Pens for Plots and other coloring has been removed for simplicity, as any use case that would use a pen can be used by a Stroke. Stroke does not need to be Frozen, and there is no special handling you need to do to serialize a Stroke

        Code:
        [Display(ResourceType = typeof(Custom.Resource), Name = "MyStroke", Order = 4, GroupName = "NinjaScriptParameters")]
        public Stroke MyStroke { get; set; }
        
        protected override void OnStateChange()
        {		 
        	if (State == State.SetDefaults)
        	{											
        		MyStroke = new Stroke(Brushes.Blue, 2);
        	}			
        }
        Aaaaargh! More rewriting. Such is the nature of Betas. Thanks for the heads-up.

        Comment


          #5
          The Stroke.Brush has a ToSharpDX helper method:

          Code:
          SharpDX.Direct2D1.Brush brush = outlineStroke.Brush.ToDxBrush(RenderTarget);
          Let me know if you have any problems with that.
          MatthewNinjaTrader Product Management

          Comment


            #6
            Thanks, works.

            Comment


              #7
              Originally posted by NinjaTrader_Matthew View Post
              The property grid was not designed to display Pens. You can used a Stroke instead which has Brush, Dash Style and Width properties.

              In fact, it is worth mentioning that in Beta 3, the concept of Pens for Plots and other coloring has been removed for simplicity, as any use case that would use a pen can be used by a Stroke. Stroke does not need to be Frozen, and there is no special handling you need to do to serialize a Stroke

              Code:
              [Display(ResourceType = typeof(Custom.Resource), Name = "MyStroke", Order = 4, GroupName = "NinjaScriptParameters")]
              public Stroke MyStroke { get; set; }
              
              protected override void OnStateChange()
              {		 
              	if (State == State.SetDefaults)
              	{											
              		MyStroke = new Stroke(Brushes.Blue, 2);
              	}			
              }
              Here is a very brief screencast showing my inablilty to display Stroke properties in an Indicator Property Grid. What am I missing? http://screencast.com/t/zuoLnZc4
              Thanks! 8.0.0.3

              Comment


                #8
                Hello dalebru,

                Please refer to my video at the following link: http://screencast.com/t/NKFVBsfuXACz

                You can also find our example at the following link: http://ninjatrader.com/support/forum...43&postcount=2
                Patrick H.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_PatrickH View Post
                  Hello dalebru,

                  Please refer to my video at the following link: http://screencast.com/t/NKFVBsfuXACz

                  You can also find our example at the following link: http://ninjatrader.com/support/forum...43&postcount=2
                  Patrick,

                  Yes, you are confirming my problem. In NT7 we could define a Pen as a property to allow the user to input not only Color but Dash style and Width. In NT8 that can't be done, apparently. We must have separate properties for Color (Brush) and width. I don't know whether a 3rd property could allow input of a Dash style.
                  Alternatively, we must add a false Plot to allow the user the input this information.
                  Thanks,
                  Dale

                  Comment


                    #10
                    Originally posted by dalebru View Post
                    Patrick,

                    Yes, you are confirming my problem. In NT7 we could define a Pen as a property to allow the user to input not only Color but Dash style and Width. In NT8 that can't be done, apparently. We must have separate properties for Color (Brush) and width. I don't know whether a 3rd property could allow input of a Dash style.
                    Alternatively, we must add a false Plot to allow the user the input this information.
                    Thanks,
                    Dale
                    In your video, you've only declared a Stroke as a property, but it was never initialized. You must create an instance of MyStroke in State.SetDefaults for that to show up.

                    Code:
                    	public class AStrokeInidcator : Indicator
                    	{
                    		protected override void OnStateChange()
                    		{
                    			if (State == State.SetDefaults)
                    			{
                                                   // this will be created on the indicator/strategy dialog and allow you to further define the color, width, dash style, etc.
                    				MyStroke = new Stroke(Brushes.Blue);  
                    			}			
                    		}
                    
                    		protected override void OnBarUpdate()
                    		{
                    			//Add your custom indicator logic here.
                    		}
                    		
                    		[Display(Name = "MyStroke", GroupName = "Display", Order = 1)]
                    		public Stroke MyStroke { get; set; }
                    	}
                    Please let me know if this does not help you achieve what you're looking to customize vs the NT7 Pen functionality.
                    Attached Files
                    MatthewNinjaTrader Product Management

                    Comment


                      #11
                      Hi,

                      What is the method to serialize a stroke ? the Serialize static class, that can be used to serialize Brushes, only contains Pen2String and String2Pen, but there seems to be no Pens any more.

                      Thanks

                      Comment


                        #12
                        Originally posted by gomifromparis View Post
                        Hi,

                        What is the method to serialize a stroke ? the Serialize static class, that can be used to serialize Brushes, only contains Pen2String and String2Pen, but there seems to be no Pens any more.

                        Thanks
                        Answer in this post in this thread.

                        ref: http://ninjatrader.com/support/forum...38&postcount=2

                        Put simply, you do not need to do anything to serialize a stroke.

                        Heck, you even thanked that post!

                        Comment


                          #13
                          Yes, sorry, didn't test native serialization... Too used to have to manually serialize graphic objects in NT7 :-)

                          Comment


                            #14
                            Originally posted by NinjaTrader_Matthew View Post
                            The Stroke.Brush has a ToSharpDX helper method:
                            Code:
                            SharpDX.Direct2D1.Brush brush = outlineStroke.Brush.ToDxBrush(RenderTarget);
                            Is that equivalent to the following?

                            Code:
                            SharpDX.Direct2D1.Brush brush = outlineStroke.BrushDX;
                            Is BrushDX SharpDX.Direct2D1.Brush or a System.Windows.Media.Brush?

                            Comment


                              #15
                              Originally posted by overflowing View Post
                              Is that equivalent to the following?

                              Code:
                              SharpDX.Direct2D1.Brush brush = outlineStroke.BrushDX;
                              Is BrushDX SharpDX.Direct2D1.Brush or a System.Windows.Media.Brush?
                              Yes.

                              BrushDX = SharpDX.Direct2D1.Brush
                              MatthewNinjaTrader Product Management

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Brillo, Yesterday, 08:47 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post Brillo
                              by Brillo
                               
                              Started by Gav_G, Yesterday, 02:12 PM
                              3 responses
                              11 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Gav_G, Yesterday, 01:41 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by kweiss, Yesterday, 01:21 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by cutzpr, Yesterday, 08:44 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X