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

Using the "dashes" parameter of the StrokeStyle constructor causes excp

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

    Using the "dashes" parameter of the StrokeStyle constructor causes excp

    Consider the following code:

    Code:
    StrokeStyle DotStrokeStyle()
    {
        StrokeStyleProperties properties = new StrokeStyleProperties()
        {
            StartCap = CapStyle.Round,
            EndCap = CapStyle.Round,
            DashCap = CapStyle.Round,
            LineJoin = LineJoin.Round,
            MiterLimit = 1.0f,
            DashStyle = DashStyle.Dot,
            DashOffset = 1.0f
        };
    
        // Doesn't seem to matter what number pattern I use here:
        float[] dashes = { 2.0f, 2.0f, 2.0f, 2.0f };
    
        // If I have the dashes parameter in the StrokeStyle constructor below, I get an exception
        // but no indication what the exception is. I also don't get a callstack. (Presumably b/c
        // this is "unsafe" code?)
        //
        // If I do NOT include the dashes parameter, I don't get an exception. I have also tried
        // using RenderTarget.Factory for kicks, but got the same result.
        return new StrokeStyle(Core.Globals.D2DFactory, properties, dashes);
    }
    Do other people see this? Am I doing it wrong?

    Cheers,
    Peter
    Last edited by carnitron; 04-30-2023, 12:39 AM.

    #2
    Apologies for the typo in the title. Fat finger mistake and I can't figure out how to fix it, lol.

    Comment


      #3
      Where is DashesCount?

      Comment


        #4
        Are you calling your method from inside OnRender?

        Comment


          #5
          Hmm, I get this stack trace,

          at SharpDX.Result.CheckError()
          at SharpDX.Direct2D1.Factory.CreateStrokeStyle(Stroke StyleProperties& strokeStyleProperties, Single[] dashes, Int32 dashesCount, StrokeStyle strokeStyle)
          at NinjaTrader.NinjaScript.Indicators.Poncho.FootPrin tChart.GetStrokeStyle()
          at NinjaTrader.NinjaScript.Indicators.Poncho.FootPrin tChart.OnRender(ChartControl chartControl, ChartScale chartScale)

          I think it's a bug in NT .. seems they're missing a constructor that
          includes the length of the dashes array.

          Comment


            #6
            carnitron bltdavid No, actually, the issue is that you are using the StrokeStyle incorrectly, although the error message could be better. If you check the documentation for DashStyle which you are sending as Dot you will see that DashStyle.Custom allows you to send the dash lengths in the dashes array parameter of a StrokeStyle constructor. If you specify the dashes array anyway but a DashStyle of DashStyle.Dot, you get an exception for invalid parameters because that combination is invalid since Dot does not have a dashes array. Try this instead:

            Code:
            #region Using declarations
            using System;
            using NinjaTrader.Gui.Chart;
            using SharpDX.Direct2D1;
            #endregion
            
            
            //This namespace holds Indicators in this folder and is required. Do not change it.
            namespace NinjaTrader.NinjaScript.Indicators
            {
                public class TestStrokeStyle : Indicator
                {
                    protected override void OnStateChange()
                    {
                        if (State == State.SetDefaults)
                        {
                            Name = "Test StrokeStyle";
                        }
                    }
            
                    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                    {
                        try
                        {
                            StrokeStyleProperties strokeStyleProperties = new StrokeStyleProperties()
                            {
                                StartCap = CapStyle.Round,
                                EndCap = CapStyle.Round,
                                DashCap = CapStyle.Round,
                                LineJoin = LineJoin.Round,
                                MiterLimit = 1.0f,
                                DashStyle = DashStyle.Custom,
                                DashOffset = 1.0f
                            };
            
                            float[] dashes = { 2.0f, 2.0f, 2.0f, 2.0f };
            
                            using (StrokeStyle strokeStyle = new StrokeStyle(Core.Globals.D2DFactory, strokeStyleProperties, dashes))
                            {
                                Print("Success");
                            }
                        }
                        catch (Exception ex)
                        {
                            Print("Exception: " + ex.Message + System.Environment.NewLine + ex.StackTrace);
                        }
                    }
                }
            }​
            You will see "Success" printed.
            Bruce DeVault
            QuantKey Trading Vendor Services
            NinjaTrader Ecosystem Vendor - QuantKey

            Comment


              #7
              Ah-hah!

              Yeah, this is one of those gotta-read-everything in the manuals
              type of problems. At least for me, it was.

              Thanks, Bruce, you are spot-on.

              Found documentation here.

              Comment


                #8
                You're welcome. Glad it's something simple.
                Bruce DeVault
                QuantKey Trading Vendor Services
                NinjaTrader Ecosystem Vendor - QuantKey

                Comment


                  #9
                  Originally posted by bltdavid View Post
                  Ah-hah!

                  Yeah, this is one of those gotta-read-everything in the manuals
                  type of problems. At least for me, it was.

                  Thanks, Bruce, you are spot-on.

                  Found documentation here.
                  bltdavid One quick note - when you paste in links like this by copying the link from the page at the right on the help or from the URL bar of your browser, the forum link doesn't work. About half the time NinjaTrader Support's links don't work either after the website redo. I usually try to get the links from the table of contents because I have better luck with those.

                  What happens is the link works when you copy/paste it into a browser tab, but once it's rendered on the forum page it's wrong.

                  For instance before I put it in a forum link it one looks like this: https[colon][slash][slash]ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?using_sharpdx_for_cu stom_chart_rendering.htm and after I do it it looks like this https://ninjatrader.com/support/help..._rendering.htm which is literally pasting the same thing without the colon slash slash having been edited out but it appends a bunch of session gibberish to the end when you try to open it, unlike the simple one which works fine.

                  Also note how it added a space between cu and storm up there even though the link itself doesn't have one. The forum is mangling the links now somehow. Even if I edit this post and take the space out, the forum puts it back (sorry for all the edits - testing this and it's true).
                  Last edited by QuantKey_Bruce; 04-30-2023, 09:33 AM.
                  Bruce DeVault
                  QuantKey Trading Vendor Services
                  NinjaTrader Ecosystem Vendor - QuantKey

                  Comment


                    #10
                    That's weird.

                    When I hover my mouse over my embedded link, Firefox previews
                    the link and shows it is correct.

                    See attached screensbot.
                    It's the bottom left corner of my FF window, previewing the link
                    before I click it,

                    Click image for larger version  Name:	IMGDT_20230430_083155.png Views:	0 Size:	8.6 KB ID:	1249061

                    When I click the link, it takes me to the permalink page I intended.

                    Which browser are you using?

                    I'll go try Chrome ...

                    Comment


                      #11
                      Originally posted by bltdavid View Post
                      That's weird.

                      When I hover my mouse over my embedded link, Firefox previews
                      the link and shows it is correct.

                      See attached screensbot.
                      It's the bottom left corner of my FF window, previewing the link
                      before I click it,

                      Click image for larger version  Name:	IMGDT_20230430_083155.png Views:	3 Size:	8.6 KB ID:	1249061

                      When I click the link, it takes me to the page I intended.

                      Which browser are you using?

                      I'll go try Chrome ...
                      I'm using the latest Chrome, and when I click on your link (or many of the links from support) it looks like this:
                      Click image for larger version  Name:	image.png Views:	0 Size:	232.4 KB ID:	1249063
                      Bruce DeVault
                      QuantKey Trading Vendor Services
                      NinjaTrader Ecosystem Vendor - QuantKey

                      Comment


                        #12
                        Okay, I fired up FireFox and the links work there. They just don't work in Chrome apparently.
                        Bruce DeVault
                        QuantKey Trading Vendor Services
                        NinjaTrader Ecosystem Vendor - QuantKey

                        Comment


                          #13
                          Chrome works fine for me.

                          I'm on Windows 7, using 'Chrome 109.0.5414.120 (Official Build) 64-bit'.

                          Let me try Chrome/FF on a Win11 box elsewhere in the house ...

                          Comment


                            #14
                            Hmm. Mine says Chrome 112.0.5615.138 (Official Build) (64-bit). I'll try a different computer. This one's on Windows 10. I'll try Windows 11.
                            Bruce DeVault
                            QuantKey Trading Vendor Services
                            NinjaTrader Ecosystem Vendor - QuantKey

                            Comment


                              #15
                              Well, I'll be darned, the exact same Chrome on Windows 11 and those links work. Okay, I'll try clearing the cache on this machine. Maybe the browser cache is messed up.

                              Well, clearing the cache, and even disabling all of my extensions in Chrome and restarting did not fix it. But not to worry, apparently the problem is unique to this machine, so sorry to bother you with this.
                              Last edited by QuantKey_Bruce; 04-30-2023, 09:53 AM.
                              Bruce DeVault
                              QuantKey Trading Vendor Services
                              NinjaTrader Ecosystem Vendor - QuantKey

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by nightstalker, 05-04-2024, 02:05 PM
                              4 responses
                              44 views
                              1 like
                              Last Post Leeroy_Jenkins  
                              Started by Drone360x, Today, 10:27 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post Drone360x  
                              Started by NUVERSA, Today, 10:08 AM
                              2 responses
                              11 views
                              0 likes
                              Last Post NUVERSA
                              by NUVERSA
                               
                              Started by truepenny, Today, 03:45 AM
                              3 responses
                              20 views
                              0 likes
                              Last Post NinjaTrader_RyanS  
                              Started by truepenny, Today, 03:59 AM
                              5 responses
                              22 views
                              0 likes
                              Last Post truepenny  
                              Working...
                              X