Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Try / catch block in NT8 reference indicator - SpreadOscillator

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

    Try / catch block in NT8 reference indicator - SpreadOscillator

    NT Forum,

    A quick thank you to NinjaTrader_Paul for the NT8 reference indicator: NT8 - Spread Oscillator. I am grateful the indicator has been posted for reference.

    The indicator uses a try/catch block for a critical section of the logic in OnBarUpdate(). While this approach works, how could the indicator be re-written without the try/catch block?

    It is my understanding exceptions should only be used when an application encounters an exceptional circumstance (MSDN). The basic rule of thumb for catching exceptions is to catch exceptions if and only if you have a meaningful way of handling them (StackOverflow). Using exceptions gratuitously is where you lose performance. For example, you should stay away from things like using exceptions for control flow (StackOverflow).

    Could IsValidDataPoint() be used?

    As always, any suggestions are welcome

    Regards
    Shannon
    Attached Files

    #2
    Hello Shansen,

    Thanks for your post.

    I did not create the indicator but converted it from the NT7 version which included the try/catch blocks.

    Doing some historical research the use of the try/catch blocks, in this case, were from initial development of the indicator and are really not needed as the Ninjascript methods are handled by the core and so the try/catch blocks can be removed. I will add this to my todo list to remove the try/catch blocks and then re-upload to the NT8 indicators forum.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CaptainJack, 05-29-2026, 05:09 AM
    0 responses
    51 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 05-29-2026, 12:02 AM
    0 responses
    30 views
    0 likes
    Last Post CaptainJack  
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    99 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    177 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    170 views
    0 likes
    Last Post CarlTrading  
    Working...
    X