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:	80
Size:	3.4 KB
ID:	1301939
    2) at the code level
    Click image for larger version

Name:	image.png
Views:	62
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 NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      53 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X