Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8 crash - detecting the underlying cause

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

    NT8 crash - detecting the underlying cause

    Hi,

    I have the following problem: I have developed an indicator which I deployed as compiled assembly to a friend in order to let him testing it. It happens - sometimes - that after the indicator is loaded onto a chart the platform crashes (i.e. it closes without any dialogs, any message, etc.). Note that it does not crash immediately, tipically the crashes occurrs in average after at least 30 minutes. The issue here is that the crash occurs only when my indicator is on a chart and I could not find neither in the trace nor in the log files any information about possible errors. In addition, on my side, I have never seen the platform crashing while the indicator is on (both in release and debug modes).

    I give here some more details:
    - for the indicator development: I have implemented it within a file under Indicator folder. It uses 3 classes developed within 3 other files located under "AddOns"; when deploying the indicator as compiled assembly I select all the 4 files for the export phase
    - the indicator is a kind of volume profile, so it works updating internal data structures at a frequency which depends on the onMarketData event. All the rendering is done within the OnRender method.
    - the indicator that I deploy is a zip file which is then imported as "Ninjascript Add on"

    My questions are:
    1) Is there any mechanism I can use to make sure that my indicator in case of internal crash does not result in a platform crash?
    2) Is there any kind of advanced tracing which I can use in order to understand which piece of code is causing the crash?

    Please let me know if you need some more information
    Thank you so much in advance for your help
    Cheers

    #2
    Hello VFI26,

    Unfortunately, there wouldn't be a mechanism to prevent the behavior of the script. Instead it will be necessary to identify what is causing the crashes and correct the code.

    If this is an actual crash with an exception error (and not a freeze where NinjaTrader becomes non-responding) you could use a try and catch around specific parts of the code (not the entire script) to see what may be causing the exception. Once identified and corrected, the try and catch should be removed for the production version of the script.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi,

      thank you!

      Actually the platform is not hanging but it terminates abnormally. Is there a way to capture the exit code? Do you have a list of error codes which may help identifying the issue?

      Cheers

      Comment


        #4
        Hello VFI26,

        Unfortunately, I do not have a list of all C# run-time error codes.

        The exception message may be shown on the Log tab of the Control Center.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Any error messages or stack traces or exceptions in the bottom of
          the trace or log files?

          Check most recent files in the trace and log folders.

          Comment


            #6
            All the today files in both of trace and log folders do not show anyinformation about errors, or any reason why the platform closes. I was wondering how can I capture exit code of ninja trader 8 and if is there any list of known error codes which I can use in order to understand the root cause of the problem

            Comment


              #7
              I throw a try/catch exception handler around most of my functions in indicators.

              Code:
              public class Logger
              {
                  public static void LogMessage(string message,
                  Exception ex,
                  [CallerMemberName] string callingMethod = null,
                  [CallerFilePath] string callingFilePath = null,
                  [CallerLineNumber] int lineNumber = 0)
                  {
                      LogMessage(string.Format("{3} | Exception ({0}) {1}: {2}", ex.GetType(), ex.Message, ex.StackTrace, message), LogLevel.Error, callingMethod, callingFilePath, lineNumber);
                  }
              
                  public static void LogMessage(Exception e,
                  [CallerMemberName] string callingMethod = null,
                  [CallerFilePath] string callingFilePath = null,
                  [CallerLineNumber] int lineNumber = 0)
                  {
                      LogMessage(string.Format("Exception ({0}) {1}: {2}", e.GetType(), e.Message, e.StackTrace), LogLevel.Error, callingMethod, callingFilePath, lineNumber);
                  }
              
                  public static void LogMessage(string message,
                  LogLevel level,
                  [CallerMemberName] string callingMethod = null,
                  [CallerFilePath] string callingFilePath = null,
                  [CallerLineNumber] int lineNumber = 0)
                  {
                      if(callingMethod != null && callingFilePath != null)
                      {
              #if !DEBUG
                          callingFilePath = Path.GetFileName(callingFilePath);
              #endif
              
                          NinjaScript.Log(string.Format("{3}\t[{0}:({1}) @ {2}]",
                          callingFilePath, callingMethod, lineNumber, message), level);
                      }
                      else
                      {
                          NinjaScript.Log("No calling information: " + message, level);
                      }
                  }
              }

              The logging functions print out the source code file name and line number. In release mode the omit the file path to reduce the burden on logging.

              The code for a OnBarUpdate would look something like this

              Code:
              protected override void OnBarUpdate()
              {
                  try
                  {
                      // do your stuff
                  }
                  catch(Exception ex)
                  {
                      Logger.LogMessage(ex);
                  }
              }
              I would do this for every function you override includong OnStateChange, OnBarUpdate, OnRender or anything you override. It may shed some light in the log/trace files as to what might be causing the crash.
              Last edited by ntbone; 11-08-2023, 08:26 AM.

              Comment


                #8
                That is great! Thank you ntbone ! May I ask you about the LogAggregateMessage method that is used in the code snippet that you have just shared? I'm asking because it is not implemented therein

                Thank you so much, really appreciated!

                Comment


                  #9
                  Sorry. I thought I had removed all references. I created another variation that would handle AggregateException and dump out the list of exceptions it stored. I only needed it in code I wrote that was throwing exceptions derived from that base class so I could see what the actual exceptions were. I updated the code in the post to remove it.
                  Last edited by ntbone; 11-08-2023, 08:27 AM.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  628 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  359 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  105 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  562 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  568 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X