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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      47 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      23 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      50 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X