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

'D2DFactory' performance and Built-in Drawing objects best practice

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

    'D2DFactory' performance and Built-in Drawing objects best practice

    Regarding the new push to make sure D2DFactory calls are only performed in UI threads (OnRender()), I want to double check the best practice of creating built-in drawing objects.

    For example, is it bad practice to call Draw.ArrowLine() from within OnBarUpdate()? Or is this acceptable?

    I didn't know if behind the scenes the built-in objects were making D2DFactory calls and thus calling them from within OnBarUpdate() would be a bad.

    Thank you!
    Last edited by neoikon; 10-15-2019, 08:46 AM.

    #2
    Hello neoikon,

    Thanks for your post.

    The change for D2DFactory is specific to custom SharpDX rendering and would not need to be minded for NinjaTrader built in drawing tools. NinjaTrader drawing tools create drawing objects that use SharpDX rendering, but the code is provided by us and the code is compliant with the D2DFactory rule.

    You may call drawing tools from OnBarUpdate and this would be appropriate use of the drawing tools.

    Please let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thank you Jim! That is what I thought, but I wanted to double check. That's great to hear.

      I have a customer that is running into the error (attached. Apologies, it's the only screenshot I have). My indicator is calling Draw.ArrowLine() and so it makes it seem like my indicator is causing the problem. However, the error message doesn't point to a specific source other than "DrawingTools.ArrowLine".

      Could it be that their @Lines.cs file was modified? Thoughts on what could be causing this error? (It happens on their machine, but not mine, which is unfortunate. We are both running 8.0.19.0)

      Brain storming...

      I have a Stroke as a user parameter and I am passing the Brush as a param to Draw.ArrowLine(). Passing myStroke.Brush, myStroke.DashStyleHelper, myStroke.Width, etc.

      I'm also calling myStroke.RenderTarget = RenderTarget; before the Draw.ArrowLine() call. Necessary? Problematic within OnBarUpdate()?

      Do I need to call myStroke.Brush.Freeze() within OnStateChange() when State == State.Configure?

      In another call I am passing Plots[2].Pen.Brush as the Brush to Draw.ArrowLine().

      Just trying to figure out what the problem could be. Does any of the above look problematic?

      Thank you again!
      Attached Files

      Comment


        #4
        Hello neoikon,

        It could be possible that the client is using an older version of @Lines.cs that has the old rendering code in place. I would suggest having them delete this file (Documents\NinjaTrader 8\bin\
        Custom\DrawingTools\@Lines.cs) and then to download an installer for NinjaTrader 8 and select Repair on the installer.

        Drawing Tools use Windows Media Brushes and are designed to be completely hands off from using SharpDX rendering. It would not be advised to re-target a Stroke's RenderTarget in OnBarUpdate, and would not be necessary in your case. OnBarUpdate runs on a thread pool for historical data processing and an instrument thread for realtime data processing. Retargeting a RenderTarget would be applicable for SharpDX rendering and would be done in OnRenderTargetChange when you need to use the Stroke's SharpDX brush.

        Freezing the Stroke's Brush property also would not be necessary as far as I have tested. The Stroke class is internal, but it appears that the brush freezing is done in the Stroke's constructor.

        If the client is able to reproduce the issue with a simple script that calls Draw.ArrowLine alone, please have them reach out to me at platformsupport [at] ninjatrader [dot] com with the text Attn Jim, the test indicator, and the ticket ID 2307410.

        Let me know if there is anything else I can do to help.
        JimNinjaTrader Customer Service

        Comment


          #5
          I have run into this same "old @Lines.cs file" issue on 2 of my 3 NinjaTrader environments. In other words, I installed 8.0.19.0 on all three of my environments, but two of them contained outdated @Lines.cs files (and other outdated files). (Plus, my customer, who ran into the same problem.)

          These old files, as the original error suggests, have D2DFactory calls within OnStateChange().

          However, updating the @Lines.cs file still creates inconsistent behavior that I'm trying to nail down.

          The fact that multiple of my environments, as well as one of my customers, are experiencing this "old file" issue seems to point to an issue with the NinjaTrader installation program.

          I've tried working with Chelsea on this issue, but I think there is a language barrier or something, because they don't read what I write. This is why I am returning to this thread.
          Last edited by neoikon; 10-17-2019, 03:26 PM.

          Comment


            #6
            Hello neoikon,

            I would recommend breaking down the script so it is a simple test case that the client can run on their end. If the issue relies on ArrowLine, please break the script down so it only has enough code to test the ArrowLine functionality. I would also recommend creating a script that uses ArrowLine by itself.

            If the client can reproduce with the test case, we can then move forward in the following ways:
            1. If the issues can be seen in a test that only includes ArrowLine, we should have what we need to assist the client from our end. Please have the client reach out to me at platformsupport [at] ninjatrader [dot] com with the text "Attn Jim 2307410" Please laos have the client link to this thread if possible.
            2. If the issue can be reproduced with a reduced version of your script that only has the needed functionality for ArrowLine, please reach out to me with this test script, and I can offer further insight on next steps or a possible resolution.
            I look forward to being of further assistance.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by TradeForge, Today, 02:09 AM
            0 responses
            0 views
            0 likes
            Last Post TradeForge  
            Started by Waxavi, Today, 02:00 AM
            0 responses
            2 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by elirion, Today, 01:36 AM
            0 responses
            4 views
            0 likes
            Last Post elirion
            by elirion
             
            Started by gentlebenthebear, Today, 01:30 AM
            0 responses
            4 views
            0 likes
            Last Post gentlebenthebear  
            Started by samish18, Yesterday, 08:31 AM
            2 responses
            9 views
            0 likes
            Last Post elirion
            by elirion
             
            Working...
            X