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

Anyone figure out SharpeDX.2DDirectX DashStyle -> dots yet?

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

    Anyone figure out SharpeDX.2DDirectX DashStyle -> dots yet?

    I have this code in OnRender():

    Code:
    SharpDX.Direct2D1.StrokeStyleProperties AsianSSProps = new SharpDX.Direct2D1.StrokeStyleProperties();
    
    switch( OvernightDashStyleSelection )
    {
        case DashStyleHelper.Dash: AsianSSProps.DashStyle = SharpDX.Direct2D1.DashStyle.Dash; break;
        case DashStyleHelper.DashDot: AsianSSProps.DashStyle = SharpDX.Direct2D1.DashStyle.DashDot; break;
        case DashStyleHelper.DashDotDot: AsianSSProps.DashStyle = SharpDX.Direct2D1.DashStyle.DashDotDot; break;
        case DashStyleHelper.Dot: AsianSSProps.DashStyle = SharpDX.Direct2D1.DashStyle.Dot; break;
        case DashStyleHelper.Solid: AsianSSProps.DashStyle = SharpDX.Direct2D1.DashStyle.Solid; break;
        default: AsianSSProps.DashStyle = SharpDX.Direct2D1.DashStyle.Solid; break;
    }
    SharpDX's dots and anything else related to dots doesn't work right. DashDotDot and DashDot and Dash all come out a little funky. Dot doesn't print at all. The only thing I can get to work right is Solid. (Note: By "properly" I mean the way Ninja's DashStyleHelper prints.)

    This is what dash and anything with Dash in it looks like:
    Click image for larger version

Name:	NQ 03-22 (10 Minute) 2021_12_29 (1_59_45 PM).png
Views:	308
Size:	22.4 KB
ID:	1183880

    Dots are simply blank, as though I rendered them invisible. Solid is the only thing that shows what you'd expect.

    My property so the user can choose the line style they prefer:
    Code:
    Display(Name = "Dash style selection", Description = "Select the dash style for the Asian line to be drawn", Order = 2, GroupName = "Asian line options")]
    public DashStyleHelper OvernightDashStyleSelection
    { get; set; }
    I've been putting up with this for a few years, not being able to figure out how to get dots to print right and finally thought I'd ask.

    Anyone figure this out yet? It would be kinda nice if all the styles worked right.

    Thanks!
    Last edited by traderpards; 12-31-2021, 03:02 PM.

    #2
    Hello traderpards,

    The other DashStyles work, but the differences may not be visible without side by side comparisons where it is easier to see each notch in the stroke and the distance between each notch.

    Example script that shows different DashStyles in use:
    Click image for larger version  Name:	NinjaTrader_2021-12-31_14-19-02.png Views:	2 Size:	100.4 KB ID:	1183883
    The results your see with DashStyle.Dot are the same as I see where the is blank. This is how the DashStyle has always worked and I have never seen it work differently. These are also SharpDX DashStyles which are not provided by NinjaScript

    For those that want to test the appearance of different SharpDX Dash Styles, you can play with code similar to the attached.
    Attached Files
    Last edited by NinjaTrader_Jim; 12-31-2021, 03:26 PM.
    JimNinjaTrader Customer Service

    Comment


      #3
      I'm not sure what you mean by "side-by-side" comparisons but clearly, the dots aren't "working." When you say, "this is how they've always worked," it seems to me you're saying they've never worked which would align with my experience.

      Can you help me figure out how to get them to work; that is how to render them in the OnRender() override? There has to be a way. To clarify, they're "working" when I can see them on the chart like I can with Draw.Line() using DashStyleHelper that Ninjatrader offers. (Note: I'm trying to purge my code of all Draw objects, which is why I need this to work.)

      Thanks!

      Comment


        #4
        traderpards - Not sure if this is relevant, but, the dash and dots etc will not work if you are drawing small segments (it does not auto stich them together). It will only work within 1 long line. So, the trick if you are drawing point to point, bar to bar, is instead to create a path geometry and draw that as 1 line. Then your dots/dash will look good. Complicated and much more work, but it's the way!

        Comment


          #5
          Originally posted by pjsmith View Post
          traderpards - Not sure if this is relevant, but, the dash and dots etc will not work if you are drawing small segments (it does not auto stich them together). It will only work within 1 long line. So, the trick if you are drawing point to point, bar to bar, is instead to create a path geometry and draw that as 1 line. Then your dots/dash will look good. Complicated and much more work, but it's the way!
          Thank you! That's what I was looking for.... I'll do that then.

          Comment


            #6
            traderpards,

            I had another look and compared with our plots when using a DashStyle of Dot. The behavior is indeed different between what NinjaTrader does for plotting and what I have attempted in my last post.

            The trick to get these to work is with setting the StrokeStyleProperties.DashCap to a desired CapStyle.

            I have some SharpDX code in a VPA indicator conversion that uses path geometry for the purpose of filling a region under a plot, it may be able to help if you want to repurpose it for a line similar to a plot like pjsmith mentions.

            You can change the DrawFigure code in it to the below to test out SharpDX.Direct2D1.CapStyle.Round.

            Code:
            private void DrawFigure(SharpDXFigure figure)
            {
                SharpDX.Direct2D1.PathGeometry geometry = new SharpDX.Direct2D1.PathGeometry(Core.Globals.D2DFactory);
                SharpDX.Direct2D1.GeometrySink sink = geometry.Open();
            
                sink.BeginFigure(figure.Points[0], new SharpDX.Direct2D1.FigureBegin());
            
                for (int i = 0; i < figure.Points.Length; i++)
                    sink.AddLine(figure.Points[i]);
            
                sink.EndFigure(SharpDX.Direct2D1.FigureEnd.Closed) ;
                sink.Close();
            
                // Create StrokeStyleProperties
                SharpDX.Direct2D1.StrokeStyleProperties ssProps = new SharpDX.Direct2D1.StrokeStyleProperties();
            
                ssProps.DashCap = SharpDX.Direct2D1.CapStyle.Round; // Change CapStyle here
            
                ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Dot;
            
                // Create StrokeStyle from StrokeStyleProperties
                SharpDX.Direct2D1.StrokeStyle strokeStyle = new SharpDX.Direct2D1.StrokeStyle(Core.Globals.D2DFact ory, ssProps);
            
                //RenderTarget.FillGeometry(geometry, dxmBrushes[figure.Color].DxBrush);
                RenderTarget.DrawGeometry(geometry, Plots[0].BrushDX, 5, strokeStyle);
                geometry.Dispose();
                sink.Dispose();
                strokeStyle.Dispose();
            }
            VPA indicator - https://ninjatraderecosystem.com/use...indicator-nt8/

            The link above is publicly available.

            The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

            JimNinjaTrader Customer Service

            Comment


              #7
              NinjaTrader_Jim Thanks! Between pjsmith for suggesting PathGeometry and you for round caps, I think I got it the best it's going to get. I imagine getting it perfect isn't possible and I don't have any problem settling for this.

              I mean, when I used RenderTarget.DrawLine() I couldn't get dots to print at all. Now they do and with round caps, they actually look like dots. So, I'm ecstatic and even though it isn't perfect, it's totally good enough for me. None of my users should have anything to complain about.

              What's not "perfect?" When you drag the x-axis the appearance of the PathGeometry changes. But it's not really a big deal to me. I made a video to show it, but I guess we're not allowed to upload videos anymore. But the user can pick between the five styles and something shows up for all of them, so I'll take it!

              So yes, it's now "figured out." Need to use PathGeometry and set the stroke style properties cap style to round caps.

              Thanks again!

              Comment


                #8
                Hello traderpards,

                If you modify VPA like I have attached here, I believe you can see the results you are looking for. A diff utility can point out the individual changes.

                I hope this helps.
                Attached Files
                JimNinjaTrader Customer Service

                Comment


                  #9
                  ssProps.DashCap = SharpDX.Direct2D1.CapStyle.Round; // Change CapStyle here

                  I could not get it to plot dots or anything to do with dots until I added this line to the styles. Also, it don't let you add it like this, now you have to do it inside the constructor like this.

                  var ss = new StrokeStyle(RenderTarget.Factory, new StrokeStyleProperties(){DashStyle = Box1StrokeStyle, DashCap = CapStyle.Round});

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by gentlebenthebear, Today, 01:30 AM
                  2 responses
                  13 views
                  0 likes
                  Last Post gentlebenthebear  
                  Started by Kaledus, Today, 01:29 PM
                  2 responses
                  8 views
                  0 likes
                  Last Post Kaledus
                  by Kaledus
                   
                  Started by frankthearm, Yesterday, 09:08 AM
                  13 responses
                  45 views
                  0 likes
                  Last Post frankthearm  
                  Started by PaulMohn, Today, 12:36 PM
                  2 responses
                  16 views
                  0 likes
                  Last Post PaulMohn  
                  Started by Conceptzx, 10-11-2022, 06:38 AM
                  2 responses
                  56 views
                  0 likes
                  Last Post PhillT
                  by PhillT
                   
                  Working...
                  X