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

OnRender Lag using Stroke

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

    OnRender Lag using Stroke

    When drawing using Stroke i'm getting a lot of lag. The chart seems unresponsive and takes several seconds to render but NT8 is not crashing. I followed the instructions here: https://ninjatrader.com/support/help...roke_class.htm



    I don't see any breakpoints being hit by my code when it is lagging. When commenting out the drawings using the Stroke and FillRectangle, everything runs normally. I'm not sure what I am doing wrong. I'm using OnRenderTargetChanged() example. Any idea how to fix this?

    #2
    Hi habibalex, thanks for your note.

    If brushes are being used inefficiently it can cause lag in OnRender. Do you have a reduced example that I could take a look at?

    I look forward to hearing from you.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      I sent an email to platformsupport and have a link to this thread in the email body.

      Also it looks like the error is related to render of StrokeStyle dashed or dotted lines. When I comment out those ones, the lag goes away.
      Last edited by habibalex; 02-15-2020, 08:48 PM.

      Comment


        #4
        Hi habibalex, thank you for your patience.

        I added a Print within OnRender and found a performance issue is coming from somewhere outside of OnRender. The file loading seems to be gumming up the system. Please look at this section of the code and optimize as much as possible.

        Please let me know if I can assist any further.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          File.ReadAllLines is part of .NET Framework so there shouldn't be any bugs there. Since it only occurs while dashed style was being drawn, I was able to narrow it down. This fixed the issue:
          Code:
          int endXpos = lev.barEnd == int.MaxValue ? (int)chartScale.Width : chartControl.GetXByBarIndex(ChartBars,lev.barEnd);
          Seems like GetXByBarIndex can't handle int.MaxValue w/ the FillRectangle and non-solid StrokeStyle. I think this is a bug.

          Comment


            #6
            Hello habibalex,

            I would not expect GetXByBarIndex() to return a value when supplied with int.MaxValue.

            GetXByBarIndex() returns an x value for a specified bar number. If you are supplying a bar number that does not exist, this will cause an error.

            The value supplied needs to be less than or equal to the value of CurrentBar.

            When supplying a value that is less than or equal to CurrentBar does this error still occur?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              No it doesn’t. Any number less than like a few hundred thousand does not produce lag. Once it gets above a certain threshold the lag starts. This only occurs with the dotted line when using the stroke object.

              Comment


                #8
                Hello habibalex,

                When you have mentioned:
                "Seems like GetXByBarIndex can't handle int.MaxValue w/ the FillRectangle and non-solid StrokeStyle. I think this is a bug."

                You are specifically saying that GetXByBarIndex() is failing when supplying int.MaxValue, is this correct?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  No, it starts failing with numbers much larger than the CurrentBar. I started w/ the the value of Int.MaxValue (2147483647) and then decreased by 10x each time until the lag was not noticeable.
                  I didn't notice any lag around 214748.

                  Comment


                    #10
                    Hello habibalex,

                    The issue may be caused by GetXByBarIndex() being misused.

                    You may be requesting the x value from bar indexes that do not exist.

                    Possibly, correcting the logic to prevent GetXByBarIndex() from being called with invalid indexes may correct the behavior.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Kaledus, Today, 01:29 PM
                    3 responses
                    9 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by frankthearm, Yesterday, 09:08 AM
                    14 responses
                    47 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by gentlebenthebear, Today, 01:30 AM
                    2 responses
                    13 views
                    0 likes
                    Last Post gentlebenthebear  
                    Started by PaulMohn, Today, 12:36 PM
                    2 responses
                    17 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