Go Back   NinjaTrader Support Forum > NinjaScript Educational Resources > Reference Samples

Reference Samples Official NinjaScript reference code samples

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 09-02-2008, 12:59 AM   #1
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,460
Thanks: 1
Thanked 171 times in 82 posts
Default Indicator: Using Try-Catch Blocks

Debugging your NinjaScript code can be time consuming and frustrating. When NinjaTrader encounters a run-time exception in your programming logic it will terminate the execution of the script and log the exception to the Control Center Log tab. This in itself can be of value however, there may be times where your script is too large and the exception error message provided is not granular enough. This is where standard C# exception handling using the keywords “try” and “catch” (try–catch block) can be very useful. A try-catch block allows you to encapsulate a section of your code to trap exceptions and write out meaningful information that can help you resolve your run-time errors.

This reference sample demonstrates the following concept:
  • try-catch blocks
Important methods and properties used include:Import instructions:
  1. Download the file contained in this thread to your PC desktop
  2. From the Control Center window, select the menu File > Utilities > Import NinjaScript
  3. Select the downloaded file
Attached Files
File Type: zip SampleTryCatch.zip (2.3 KB, 1426 views)
NinjaTrader_Josh is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Josh for this post:
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Indicator: Removing and Custom Formatting an Indicator’s Chart Label NinjaTrader_Josh Reference Samples 0 12-30-2007 07:49 PM
Strategy Catch Up ohowie Suggestions And Feedback 5 12-30-2007 07:46 PM
Once NT6 data becomes delayed it doesn't catch up to be real-time dfogg Connecting 11 08-17-2007 07:41 AM
Catch the end of a minute bar on a tick by tick OnBarUpdate event Fabrice Automated Trading 5 07-06-2007 12:28 PM
Catch the end of a minute bar on a tick by tick OnBarUpdate event Fabrice Automated Trading 1 07-06-2007 06:53 AM


All times are GMT -6. The time now is 10:43 PM.

FULL RISK DISCLOSURE: Futures trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.