Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to force exit position rather than system crash if stop is above market price

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

    How to force exit position rather than system crash if stop is above market price

    Hi,

    I have been running into issues with my strategy when my exit stop price is above the current market price (if long, or the opposite if short). This is a strategy based on end of day data, and so when I submit an order there can often be a large gap overnight.

    I calculate the stop price based on the last close; for example, if the last price was $25, I might submit a stop of $24.50. This is a strategy based on end of day data, and so when I submit an order there can often be a large gap overnight that results in my intended stop price being above the current market price.

    I submit a new stop price every day (to mimic a trailing stop, but submitted manually). Any time that I try to use tight stops though, I run into issues. I have scoured this forum, and spent a lot of time trying to program error handling in the OnOrderUpdate section, but nothing that I do seems to fix this issue.

    What I am wondering is: How would I go about programming NinjaTrader such that if I try to submit a stop order that is above the current market price, it will just exit the position that I'm applying the stop to? (Rather than throw an error that aborts the strategy?)

    Thanks

    #2
    Hello kbeary33,

    Thank you for your post.

    There is no method to override the error handling in NinjaTrader to work around rejection messages that stop your strategy. You may wish to program some additional logic to take into consideration such gaps in price, or even use the overnight session data to help in these calculations.

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

    Comment


      #3
      Originally posted by kbeary33 View Post
      Hi,

      I have been running into issues with my strategy when my exit stop price is above the current market price (if long, or the opposite if short). This is a strategy based on end of day data, and so when I submit an order there can often be a large gap overnight.

      I calculate the stop price based on the last close; for example, if the last price was $25, I might submit a stop of $24.50. This is a strategy based on end of day data, and so when I submit an order there can often be a large gap overnight that results in my intended stop price being above the current market price.

      I submit a new stop price every day (to mimic a trailing stop, but submitted manually). Any time that I try to use tight stops though, I run into issues. I have scoured this forum, and spent a lot of time trying to program error handling in the OnOrderUpdate section, but nothing that I do seems to fix this issue.

      What I am wondering is: How would I go about programming NinjaTrader such that if I try to submit a stop order that is above the current market price, it will just exit the position that I'm applying the stop to? (Rather than throw an error that aborts the strategy?)

      Thanks
      Use a try...catch block, catch the exception, and issue a Mar****rder in the exception block.

      While this is one way to do it, one should be very wary of trapping exceptions that NT handles natively. So, do plenty of testing for side-effects. Then do more testing.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      639 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      366 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      107 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      569 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      572 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X