Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trying to avoid NT8 crashes

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

    Trying to avoid NT8 crashes

    Hi,

    I'm trying to determine the cause why eventually NT8 triggers such an exception when running some strategies that even Windows7 crashes.

    In order to do that I'm trying to isolate those situations and identify the problem either for avoid them of for at least catch and manage them so the strategy be able to go on without making everything crash.

    In first place I need to stop the strategy as soon as an exception is detected to be able to study it, so I need:

    - To know how could I invoke strategy's CloseStrategy() method from an indicator it is using, since it seems that it's in the indicators code where the problem is, so I can stop the strategy in that moment and avoid the crash and try to study it.

    - To know what files uses NT8 to log the information about exceptions/crashes, so I could get more information besides the one I'll print in the catch snippet.

    - Any idea on making easier to identify the problem (NT8 debug tips...) will be welcomed.

    I'll appreciate the help of someone with experience on this kind of issues, since it's being quite hard to me to keep on using NT8 as platform for my strategies due to the several problems I'm finding (I understand it's a new platform, but it's being a bit painful) and I wish to solve them as soon as possible.

    Thanks in advance.

    #2
    Hello manugarc,

    Thanks for writing in.

    - To know how could I invoke strategy's CloseStrategy() method from an indicator it is using, since it seems that it's in the indicators code where the problem is, so I can stop the strategy in that moment and avoid the crash and try to study it.
    This would not be possible to have the indicator call a function of a strategy. You will be able to debug this by placing Print() statements in the the indicator in question so you can observe the logic that is being processed. I also suggest to use TraceOrders to observe the order filling logic to understand "when" these errors occur. This information can be viewed from the NinjaScript Output Window.

    - To know what files uses NT8 to log the information about exceptions/crashes, so I could get more information besides the one I'll print in the catch snippet.
    Unhandled exceptions and other errors can be found in the NinjaTrader Log and Trace files and in the Log tab of the NinjaTrader Control Center. Log and trace files can be found in the "Documents/NinjaTrader 8/log" and "Documents/NinjaTrader 8/trace" folders.

    - Any idea on making easier to identify the problem (NT8 debug tips...) will be welcomed.
    Extensive debugging tips for debugging NinjaScripts can be found below.

    Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

    TraceOrders: http://ninjatrader.com/support/forum...ead.php?t=3627

    Please let me know if I may be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim,

      Thank you for the information. I didn't know about "log" and "trace" files; that will make my work much easier.

      I'll try to identify the problem(s) this week, but in the meanwhile, since I guess the problems come from either some code trying to access an index which still doesn't exist (for example another instrument's value on [0] when it still doesn't have any value for the current bar) or when trying to get a value from an indicator when it still hasn't calculated the current value([0]), I'm asking you about some link (if it has already been discussed con this forum) regarding to:

      - Some way of check whether another instrument different than the chart one or just any other array (from a indicator or whatever) has a value on position [0], and in case it doesn't, try to get the newest value, from [1], [2], or even [100]; in short: When [0] is empty, get the newest value, no matter how older, but get a value instead of getting a null or an exception.

      - How to be absolutely sure, when using indicators into a strategy, that those indicators have finished their calculations for the current bar prior to execute OnBarUpdate() strategy method.

      Thanks in advance for your time.

      Comment


        #4
        Hello manugarc,

        Thanks for the reply.

        Generally the solution for indexing errors is to add a return condition that prevents execution when enough bars might not exist.

        For example you can use a condition that checks if the CurrentBar is greater than a certain value to ensure that enough data exists to satisfy your indicators' assigned periods. For example, if you try to perform an SMA with a period of 20, you will need to make sure 20 bars have passed before calculating.

        Code:
        if (CurrentBar < 20)
        	return;
        Creating a return condition like the above as the first statement in OnBarUpdate() should correctly fix the example issue I described. In words, the solution is to logically prevent references when the data does not exist and the reference will be invalid.

        You may also wish to use IsValidDataPoint() to verify that the data exists before you reference and use it. Please consider the following example from the help guide:

        Code:
        protected override void OnBarUpdate()
        {
          // only set plot value if hosted indicator is not reset
          if(SMA(20).IsValidDataPoint(0))
            MyPlot[0] = SMA(20)[0];     
        }
        IsValidDataPoint() - http://ninjatrader.com/support/helpG...ddatapoint.htm

        If you wish to have code that checks a certain value and then checks another value if there was an issue accessing the first value, you may wish to investgate using try, catch blocks within your strategy. I recommend the former as a solution to indexing issues, however.

        Try, Catch blocks - http://ninjatrader.com/support/forum...ead.php?t=9825

        - How to be absolutely sure, when using indicators into a strategy, that those indicators have finished their calculations for the current bar prior to execute OnBarUpdate() strategy method.
        When an indicator is called within OnBarUpdate() it is processed with all the data available at the time OnBarUpdate() is called. The workflow is as follows:
        • Data is received.
        • Bar is completed.
        • OnBarUpdate() is called.
        • Indicators called within OnBarUpdate() have the same data available as OnBarUpdate().
        • Indicator returns current value based on the available data.
        • OnBarUpdate() continues.


        Since the indicator gets updated with the available data within the OnBarUpdate() call, there will not be a need to check if the indicator has finished its calculations.

        Please let me know if you have any other questions.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hello Jim,

          I've got this error while launching a number of strategies; I think this one has nothing to do with the ones I was talking about, but I let you know it since I'm not sure whether it's related and to ask you whether it could be avoided (It doesn't make Windows crash but NT8).

          Code:
          2017-04-04 00:30:02:580 *************** unhandled exception trapped ***************
          2017-04-04 00:30:02:580 The calling thread cannot access this object because a different thread owns it.
          2017-04-04 00:30:02:580 System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it.
             at MS.Internal.TextFormatting.TextMetrics.FullTextLine.DrawTextLine(DrawingContext drawingContext, Point origin, MatrixTransform antiInversion)
             at MS.Internal.TextFormatting.TextMetrics.FullTextLine.Draw(DrawingContext drawingContext, Point origin, InvertAxes inversion)
             at #m3b.#l3b.#p3b.#2hc(ITextView #N5b, Rect #adc)
             at #m3b.#l3b.#2hc(ITextView #N5b, Rect #adc)
             at ActiproSoftware.Windows.Controls.SyntaxEditor.Primitives.EditorView.RenderLines()
             at ActiproSoftware.Windows.Controls.SyntaxEditor.Primitives.EditorView.PerformViewLineLayout()
             at ActiproSoftware.Windows.Controls.SyntaxEditor.Primitives.EditorView.set_FirstVisiblePosition(TextPosition value)
             at ActiproSoftware.Windows.Controls.SyntaxEditor.Primitives.EditorView.ScrollVerticallyByLine(Int32 lineDelta)
             at ActiproSoftware.Windows.Controls.SyntaxEditor.Primitives.EditorView.ProcessOnMouseWheel(MouseWheelEventArgs e)
             at ActiproSoftware.Windows.Controls.SyntaxEditor.Primitives.EditorView.OnMouseWheel(MouseWheelEventArgs e)
             at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
             at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
             at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
             at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
             at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
             at System.Windows.Input.InputManager.ProcessStagingArea()
             at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
             at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
             at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
             at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
             at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
             at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
             at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
             at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
          Last edited by manugarc; 04-03-2017, 05:12 PM.

          Comment


            #6
            Hello manugarc,

            Without the full code I’m unable to test on my end. Furthermore, debugging customer code is out of the scope of NinjaScript support. However, if you’d like I could have someone from our business development team pass over a list of third party developers that you could contact about debugging your code. If that is the case, you can write into platformsupport[at]ninjatrader[dot]com with a link to this thread and the text "Attn Jim."

            I would suggest using the debugging tips referenced in my 2nd post so you can determine where the issue is occurring. You can comment out code that you know to be working and place Print() statements to monitor where the code is executing in your strategy. Once you identify problematic sections, you can verify those lines are written correctly and your logic does not allow corner case run time errors to occur.

            I am curious about the issue you are having with threading, and I think it would be valuable if you shared your debugging experience with other clients in this thread.

            You may wish to review the considerations for Multi Threading in NinjaScript when debugging this issue. I will provide a link: http://ninjatrader.com/support/helpG...-threading.htm

            We have had users write in about similar issues in the past involving ActiPro. You may also wish to try reinstalling your platform to attempt to fix this issue.

            Please follow the steps listed below to cleanly uninstall and reinstall NinjaTrader.
            • Close all running applications.
            • Uninstall NinjaTrader within Windows Control Panel.
            • Reboot your machine.
            • Once these steps are completed, download the NinjaTrader installer from the link below.
            • http://ninjatrader.com/PlatformDirect

            A thread where where other users have posted on this can be found here: http://ninjatrader.com/support/forum...ad.php?t=83303

            Please let us know if you need further assistance.
            Last edited by NinjaTrader_Jim; 04-04-2017, 10:24 AM.
            JimNinjaTrader Customer Service

            Comment


              #7
              Hello Jim,

              I'm glad you are curious about these issues since I want to go back to them in the near future At this moment I'm in a hurry and need either to have NT8 working without crashing or translate my strategies back to another platform, so I can't stop to check exceptions like this one because only happens from time to time, but I'll code and send you some code snippets in order to try to let you test them in your end as soon as I have NT8 working and my strategies on again.

              Not only I use it, but I've always recommended using Print() as the best way to debug code; problem here is that I would need to write data to files since when NT8 crashes I'm not able to check the Output Window, and that's why I asked you about log files (I was looking for the wrong ones).

              Many thanks for your comments, tips and links, are truly useful.

              I've achieved to avoid some problems though there is one I don't know how to fix, it's this one:

              Code:
              2017-04-12 21:43:00:581|1|64|Instrument='USDJPY' Account='Account1' Average price=109.40025 Quantity=100.000 Market position=Long Operation=Update
              
              2017-04-12 21:43:00:591|3|4|Chart style 'Candlestick': Error on calling 'OnRender' method: System.NullReferenceException: Object reference not set to an instance of an object.    at NinjaTrader.NinjaScript.ChartStyles.ChartStyle.RenderTrades(ChartControl chartControl, ChartScale chartScale, ChartBars chartBars)    at NinjaTrader.NinjaScript.ChartStyles.ChartStyle.Render(RenderTarget pRenderTarget, ChartControl chartControl, ChartScale chartScale, ChartBars chartBars)
              It happens quite frequently (at least 1 time per day) and I'm not sure whether this is the cause, but I believe that 100% of times this happens, NT8 begins to increase it's used RAM (I've seen it using 4GB when usually it uses around 350 MB) and later on it crashes (it crashes not because of the consumed RAM, or at least not only because of that, since many times it happens when it is still only using 100MB above normal(450MB)).

              For more information, when this happens, in the chart where this error happens every candle is deleted and only some vertical lines the system has drawn keeps visible (just 3 or 4 in a day, not enough to be a problem I think). Also, I don't draw or paint anything when an order is placed; I mean I can't stop doing nothing to try to avoid this error since all I/the strategy does is to place the order.

              Would it be possible to change or avoid the texts and arrows NT8 draws when an order is placed just in case it was the cause (since I don't understand what else could be)?
              Last edited by manugarc; 04-12-2017, 07:10 PM.

              Comment


                #8
                Hello manugarc,

                Thanks for reaching back.

                The error you are receiving is from OnRender(). If you are using this overload, you can comment out sections of code to determine which line is throwing the null exception. Using a null check or IsValidDataPoint() should be able to resolve the issue for the problematic line.

                Code:
                if (myVar ! null)
                    int myVar2 - myVar;
                If you wish to catch where your code is at before it crashes, you can also use the Log() method to store information to the Log file.

                Log() - https://ninjatrader.com/support/help...en-us/?log.htm

                If you have been unable to resolve your inquiry and have bare bones sample code that defines the issue, I will be happy to take a look if the behavior is expected.

                Please let me know if I may be of further help.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Hi Jim,

                  Sure, the exception is thrown on OnRender(). What code do you suggest me to use to override it and try to isolate the problem?

                  Thanks.

                  Comment


                    #10
                    Hello manugarc,

                    My suggestion was simply to begin looking there if you have an override for OnRender() in your code.

                    If the exception is getting thrown there when you have not added an override for OnRender(), I am especially curious. I would want to take a look at any bare bones sample code that expresses this issue.

                    I look forward to looking into this matter on my end after you have created a sample I can use to test with.
                    JimNinjaTrader Customer Service

                    Comment


                      #11
                      Ok, so I guess there is some kind of misunderstood; maybe my fault, excuse my english. I though you were suggesting me to override OnRender() to debug it (it looks to me a good idea indeed), but I think you believe I've already override it; I have not, that's why I wasn't able to do anything more than asking for help

                      EDIT: Right now I find quite hard to create a sample code since my strategy is too big in code to simplify it, specially when I don't know where could be the problem, but it works with more than only 1 instrument on the chart; not sure about that could be part of the problem, but after thinking about it for a long time, I don't find anything else "special" on my strategy leaving apart its internal logic.

                      EDIT2: In short: All I do regarding to visual objects is to draw some vertical lines (really few) and the messages NT places on the chart when the strategy sends the orders.
                      Last edited by manugarc; 04-13-2017, 02:16 PM.

                      Comment


                        #12
                        Hi Jim,

                        I've simplified my strategies to the maximum; now they just draw some vertical lines (less than 10 per day in a 1 minute-bar chart each one), to be sure what's the problem, and after 20 hours of having them running here I have it:

                        Code:
                         2017-04-21 05:46:28:011|3|16|Failed to call OnRender() for chart object 'Vertical Line': 'External component has thrown an exception.'
                        That's all the content on the log file, no more lines or messages.

                        This makes NT8 (latest version) crash.

                        I would appreciate a sincere answer; Is it possible to avoid these crashes as far as you know?
                        Can I have an OnRender() code which Try/Catch on these exceptions?
                        Do you think is there any way to keep on using NT8 without getting these exceptions?

                        Thanks in advance.
                        Last edited by manugarc; 04-20-2017, 10:15 PM.

                        Comment


                          #13
                          Hello ManugarC and Jim,

                          I also have intermittent crashes due to a similar error thrown on the horizontal lines, or if I try to adjust the colour of a draw object.

                          Code:
                          21/04/2017 07:38:12	NinjaScript	Failed to call OnRender() for chart object 'Horizontal Line': 'External component has thrown an exception.'
                          I suspect it may have started when I used SIM22_DrawingToolbarV3 Indicator, but I cannot be sure, as although removing it reduces the occurrences, the errors still happen.

                          Comment


                            #14
                            Hello manugarc and GeorgeW,

                            In order to assist further, I must see how you are producing these errors.

                            Could you provide me an indicator or strategy that only has logic to place these drawing objects and produce the error? Providing debug assistance is outside the scope of our support, so I would only offer my opinion of the errors received. We are not equipped to design strategies or indicators to reproduce scenarios described by our clients. This is where we would require a test case from you to investigate further.

                            I would appreciate a sincere answer; Is it possible to avoid these crashes as far as you know?
                            I would need to have a complete understanding of how you are reproducing this error before I can offer any suggestions.

                            Can I have an OnRender() code which Try/Catch on these exceptions?
                            You can add Try/Catch blocks to code within OnRender(), but if you are not overriding it and placing your own code there, there would not be much reason to consider this.

                            Do you think is there any way to keep on using NT8 without getting these exceptions?
                            We will have to know how you are producing these errors if you would like to correct them.

                            I look forward to being of further help.
                            JimNinjaTrader Customer Service

                            Comment


                              #15
                              Hi Jim,

                              Well, there is not much more to say; the strategy draws vertical lines and that makes NT8 crash.

                              I guess you can reproduce it by using a code which draw lines, as my strategies do.

                              I was asking you about the OnRender() function code to debug it by myself since now I don't know what code do you use.

                              "Providing debug assistance is outside the scope of our support" Please have in mind I'm not asking for debugging my code but yours. The exception is not generated by any of my functions but by OnRender() when a vertical/horizontal line is drawn. Being a version "stable", this shouldn't be happening.
                              Last edited by manugarc; 04-21-2017, 02:47 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by TraderCro, 04-12-2024, 11:36 AM
                              4 responses
                              69 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Mindset, Yesterday, 02:04 AM
                              1 response
                              15 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by agclub, 04-21-2024, 08:57 PM
                              4 responses
                              18 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by Irukandji, Today, 04:58 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Irukandji  
                              Started by fitspressoburnfat, Today, 04:25 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post fitspressoburnfat  
                              Working...
                              X