• 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

Custom Render - Example

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

    Custom Render - Example

    Ninja Support team - Have used custom graphics in Ninja 7 but having little difficulties to replicate in Ninja 8 Custom Render.

    Would you please post an example to draw the following if possible.

    - Draw a "dashed" line/rectangle with thickness of 1 & 2
    - Draw a "dashed dot" line/rectangle with colors Green & Red

    thanks

    #2
    After some experiments, I ended up adding a plot and handling the StrokeStyle using Plots[0].StrokeStyle. But some how couldn't get the required result using "Stroke" Variable.

    this bring up couple of questions:

    - Is it "mandatory" to use a Plot?
    - Is not - is it possible to define/use StrokeStyle (DashDot/Dot) etc dynamically and use with DrawLine under render section?

    thanks

    Comment


      #3
      Hello,

      Thank you for the questions.

      You would need to use the StrokeStyleProperties object to control the Style of a stroke when using OnRender. This is highly different that the Plots as the Plots are made to be simple.

      It is not mandatory to use a plot, Plots would have different uses in general than OnRender, OnRender is specifically made for drawing on the chart where a Plot both Draws on a chart and is a Series in which you can access historical values.


      Here is a sample of drawing a dashed line from OnRender:

      Code:
      			
      SharpDX.Direct2D1.StrokeStyleProperties ssProps = new SharpDX.Direct2D1.StrokeStyleProperties();
      ssProps.StartCap = SharpDX.Direct2D1.CapStyle.Round;
      ssProps.EndCap = SharpDX.Direct2D1.CapStyle.Round;
      ssProps.DashOffset = 0.1f;
      ssProps.DashStyle = DashStyle.Dash;
      			
      			
      SharpDX.Direct2D1.StrokeStyle myStyle = new SharpDX.Direct2D1.StrokeStyle(RenderTarget.Factory, ssProps);
      RenderTarget.DrawLine(new Vector2(0,0), new Vector2(100,100), Brushes.Red.ToDxBrush(RenderTarget),  1, myStyle);
      This is the original post in which this sample stems from: http://ninjatrader.com/support/forum...69&postcount=2


      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #4
        vking,
        You may well already know this....but if you want to set up a configurable 'stroke' you can add this to your Properties ...
        PHP Code:
        [NinjaScriptProperty]
        [
        Display(ResourceType typeof(Custom.Resource), GroupName="Basic"Name "...myStroke"Order 25Description="")]
        public 
        Stroke myStroke 
        getset; } 
        ...and then add this to OnStateChange()...(to set default values
        PHP Code:
        if (State == State.SetDefaults)
        {
             
        myStroke  = new Stroke() { Brush Brushes.BlackWidth 2DashStyleHelper DashStyleHelper.Dash };

        ...after which you can reference 'myStroke' in your OnRender section
        Last edited by photog53; 01-04-2016, 12:12 PM.

        Comment


          #5
          Thank you Jesse & Photog53. Appreciate the replies.

          These were the exact solutions I was looking for.

          Thank you.

          Comment


            #6
            Jesse - From the code you have posted - There is property called - DashStyle.Dash.

            SharpDX.Direct2D1.StrokeStyleProperties ssProps = new SharpDX.Direct2D1.StrokeStyleProperties();
            ssProps.StartCap = SharpDX.Direct2D1.CapStyle.Round;
            ssProps.EndCap = SharpDX.Direct2D1.CapStyle.Round;
            ssProps.DashOffset = 0.1f;
            ssProps.DashStyle = DashStyle.Dash; // This is NOT A valid Style


            Would you please suggest the correct way to use this ?

            Thanks

            Comment


              #7
              Hello,

              Excuse me for that, I already had the using statements in my script so I had failed to see that.

              Here is the corrected code that uses the fully qualified names.


              Code:
              SharpDX.Direct2D1.StrokeStyleProperties ssProps = new SharpDX.Direct2D1.StrokeStyleProperties();
              ssProps.StartCap = SharpDX.Direct2D1.CapStyle.Round;
              ssProps.EndCap = SharpDX.Direct2D1.CapStyle.Round;
              ssProps.DashOffset = 0.1f;
              ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Dash;
              						
              						
              SharpDX.Direct2D1.StrokeStyle myStyle = new SharpDX.Direct2D1.StrokeStyle(RenderTarget.Factory, ssProps);
              RenderTarget.DrawLine(new SharpDX.Vector2(0, 0), new SharpDX.Vector2(100, 100), Brushes.Red.ToDxBrush(RenderTarget), 1, myStyle);
              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Thank you Jesse. Appreciate it.

                It appears like - myStyle is a disposable item. Do we need to include "myStyle.Dispose();" as well in the render function?

                Thanks

                Comment


                  #9
                  Hello,

                  Thank you for the reply.

                  In general you should dispose of items if they are disposable, there is a post on this topic here: http://ninjatrader.com/support/forum...hlight=Dispose

                  The sample I provided was only a quick sample so I did not dispose but in a real world scenario, disposing of anything that is disposable after it has been used is a good practice.

                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    This very helpful as I too was trying to figure out how to render DashStyleHelper options in OnRender(). But something isn't right. I used the very same code sample Jesse offered plus this (Style is a property option from the user):
                    Code:
                    private SharpDX.Direct2D1.DashStyle getDashStyle()
                    {
                    	if( Style == DashStyleHelper.Solid ) {
                    		return 	SharpDX.Direct2D1.DashStyle.Solid;
                    	}
                    	else if( Style == DashStyleHelper.Dash ) {
                    		return 	SharpDX.Direct2D1.DashStyle.Dash;
                    	}
                    	else if( Style == DashStyleHelper.DashDot ) {
                    		return 	SharpDX.Direct2D1.DashStyle.DashDot;
                    	}
                    	else if( Style == DashStyleHelper.DashDotDot ) {
                    		return 	SharpDX.Direct2D1.DashStyle.DashDotDot;
                    	}
                    	else if( Style == DashStyleHelper.Dot ) {
                    		return 	SharpDX.Direct2D1.DashStyle.Dot;
                    	}
                    	else {
                    		return 	SharpDX.Direct2D1.DashStyle.Solid;				
                    	}			
                    }
                    The styles DashDot, DashDotDot and Dash all look the same and Dot doesn't even show up. Is that something we can help or is that on SharpDX?

                    Comment


                      #11
                      Hello traderpards,

                      Thank you for your post.

                      Have you tried just setting the DashStyle without your getDashStyle() method being used? Do you still see the same behavior?
                      Patrick H.NinjaTrader Customer Service

                      Comment


                        #12
                        Just tried it. Since it just an enumeration I didn't think it would make a difference and sure enough, it didn't. Everything looks like dashes and the dot doesn't even show up.

                        Comment


                          #13
                          Hello,

                          Could you post a sample script of what you are currently trying that is not working? I would like to try what you are on my end as you are, and then based on that I could determine what is not working correctly and submit it if needed.

                          I look forward to being of further assistance.
                          JesseNinjaTrader Customer Service

                          Comment


                            #14
                            This shows it...
                            Attached Files

                            Comment


                              #15
                              Hello,

                              Thank you for the sample, this helped in seeing what code was being used and why it was not working.

                              When using Dot specifically with the settings included, it looks that the DashOffset being used is not allowing the dots to be visible. removing this property when Dot is used seems to resolve it not being displayed. Additionally when removing this property I do see differences in all of the styles.

                              With the SharpDX items, because there is limited documentation on these from the developer of sharpdx, it is hard to say exactly what is needed for each of these to work correctly as the original post did not account for this.

                              I do see when searching the NinjaTrader custom project that DashStyle specifically is never used and was only used in the example posted on the forum here: http://ninjatrader.com/support/forum...69&postcount=2

                              I see internally it looks like all of the Drawing tools and other items that use OnRender use DashStyleHelper instead.

                              It looks like the Styles from the previous examples can be ignored and the following could be used instead to be more in line with how the existing items already do this, for further samples please review the existing drawing objects and their OnRender code.

                              Code:
                              StrokeStyle strokeStyle = new Stroke(Brushes.Gray, DashStyleHelper.Dot, 5f).StrokeStyle;
                              Instead of using StrokeStyleProperties a Stroke can be used and its StrokeStyle property could be used:

                              Code:
                              StrokeStyle strokeStyle = new Stroke(Brushes.Gray, DashStyleHelper.Dot, 5f).StrokeStyle;
                              RenderTarget.DrawLine(new SharpDX.Vector2(0, 0), new SharpDX.Vector2(100, 100), Brushes.Red.ToDxBrush(RenderTarget), 1, strokeStyle);

                              I look forward to being of further assistance.
                              JesseNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by psquare, Today, 03:11 PM
                              4 responses
                              15 views
                              0 likes
                              Last Post psquare
                              by psquare
                               
                              Started by ballboy11, Today, 03:20 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by tonynt, Today, 02:18 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_JoshG  
                              Started by denalek2419, Today, 01:46 PM
                              3 responses
                              12 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Started by REI140205, Today, 12:58 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Jim  
                              Working...
                              X