Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to handle strategy crashes with pending orders?

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

    How to handle strategy crashes with pending orders?

    Scenario I encountered during my forward testing:
    1. When I got a signal to go long, I will submit order for long limit entry. Once the long limit entry is filled, I submitted a pair of profit taking and stop loss orders.
    2. I encountered an exception/error and my strategy was disabled. However my long position and pair of bracket orders are still alive.
    3. Price move to hit my stoploss and the position is closed.
    4. Price then move towards my profit taking and new short position is being initiated. (If my strategy is still alive, this profit taking order would have already being cancelled at step3)
    5. At the end of the day I ran into a big red P&L due to the unwanted position.
    Question: is there anyway to trigger a flatten / cancel all at the very instant my strategy is being disabled by the platform? I have a ready flatten/cancel all method, just not sure if I am able to activate it during a strategy crash/or when strategy is being disabled.
    Last edited by elirion; 05-02-2024, 03:23 AM.

    #2
    Hi Brandon,

    I am using Exit methods for my stoploss and profit target orders

    The error i encountered is: https://forum.ninjatrader.com/forum/...ror-on-barsago
    However I can never simulate the problem again with replay function.

    The error message is not important, I want to cater to ALL sort of errors that can potentially CRASH my strategy and left my positions and orders hanging in the air.

    I have done these steps, please comment if they are viable:

    1) under tools: options: strategies:
    Click image for larger version

Name:	image.png
Views:	84
Size:	3.4 KB
ID:	1301939
    2) at the code level
    Click image for larger version

Name:	image.png
Views:	67
Size:	6.6 KB
ID:	1301940
    ​I am testing with positive result, I can fatten my positions and cancel all pending orders. I can only test by disabling the strategy manually. Do you have any suggestion for me to simulate a real crash within the strategy ?

    Comment


      #3
      Hi Brandon, yes CancelFlatten() and SendStrategyTerminationAlert() are my custom method.

      I will study Chelsea's advice and your recommendation for forced disable of strategy.

      thank you both of you

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      20 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      48 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      38 views
      0 likes
      Last Post CarlTrading  
      Working...
      X