Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

order rejected - strategy crashes - what kind of exceptions

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

    order rejected - strategy crashes - what kind of exceptions

    Hello,
    I went live for the first time today on a strategy I have been developing (after much sim account testing) and I ran into a problem when my strategy submitted an order. The order was rejected and immediately crashed my strategy.

    The reason (it appears right now at least) the order was rejected was because it tried submitting an order size that violated my accounts "precautionary settings" on my brokers side. So I have increased that limit and I hope things will play out as planned tomorrow.

    The question I have is, what sort of error handling should I think about when placing orders so my strategy will not crash on a rejected order or something similiar? Standard try/catch block? Any reference of specific error codes I can account for? Also any other suggested areas to insert try/catch blocks that otherwise would not have had a problem in regular sim account testing?

    Thanks!

    #2
    Originally posted by slocumtrader View Post
    Hello,
    I went live for the first time today on a strategy I have been developing (after much sim account testing) and I ran into a problem when my strategy submitted an order. The order was rejected and immediately crashed my strategy.

    The reason (it appears right now at least) the order was rejected was because it tried submitting an order size that violated my accounts "precautionary settings" on my brokers side. So I have increased that limit and I hope things will play out as planned tomorrow.

    The question I have is, what sort of error handling should I think about when placing orders so my strategy will not crash on a rejected order or something similiar? Standard try/catch block? Any reference of specific error codes I can account for? Also any other suggested areas to insert try/catch blocks that otherwise would not have had a problem in regular sim account testing?

    Thanks!
    Look at the NT Help entry for RealtimeErrorHandling. It has a quite good example of how to handle this if you do not want the strategy to terminate on errors. Be careful!

    ref: http://www.ninjatrader.com/support/h...=errorhandling

    Comment


      #3
      Originally posted by slocumtrader View Post
      Hello,
      I went live for the first time today on a strategy I have been developing (after much sim account testing) and I ran into a problem when my strategy submitted an order. The order was rejected and immediately crashed my strategy.

      The reason (it appears right now at least) the order was rejected was because it tried submitting an order size that violated my accounts "precautionary settings" on my brokers side. So I have increased that limit and I hope things will play out as planned tomorrow.

      The question I have is, what sort of error handling should I think about when placing orders so my strategy will not crash on a rejected order or something similiar? Standard try/catch block? Any reference of specific error codes I can account for? Also any other suggested areas to insert try/catch blocks that otherwise would not have had a problem in regular sim account testing?

      Thanks!
      The default behavior of strategies is to stop the strategy when you receive an error. This should prevent it from taking further action, however may be what you're saying crashed.

      As koganam mention, you can disable this behavior by changing the error handling property, but you will have to handle your own actions should the strategy receive errors. The strategy will then keep running and take instruction to handle these situations as you have coded.

      If I'm mistaken and you have already asked the strategy to keep running, but your strategy crashed for other reasons, then you would want to consider adding try-catch blocks to prevent the crash.

      In your situation, you could check for a rejected state as we demonstrate in our sample:

      Code:
      protected override void OnOrderUpdate(IOrder order) 
      { 
          if (stopLossOrder != null && stopLossOrder == order) 
          {
              // Rejection handling 
              if (order.OrderState == OrderState.Rejected) 
               {
                    // Stop loss order was rejected !!!! 
                    // Do something about it here 
               } 
          }
      }
      ref: http://www.ninjatrader.com/support/h...orhandling.htm
      MatthewNinjaTrader Product Management

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      668 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      377 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      110 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      575 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      580 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X