Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    Hello elirion,

    Thanks for your post.

    Are you using Set methods or Exit methods for your stop loss and profit target orders?

    What exactly did the error message state so we may accurately assist?

    Please send a screenshot of the error message in question.
    • To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.
    • Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save it as a jpeg file and send the file as an attachment.
    ​We look forward to assisting further.
    Brandon H.NinjaTrader Customer Service

    Comment


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

Name:	image.png
Views:	14
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


        #4
        Hello elirion,

        Thanks for your notes.

        You could Enable the NinjaScript Options to cancel entry orders and exit orders when the strategy is disabled if you want to have those orders canceled when a disable occurs.

        Understanding NinjaScript Strategy Option Properties: https://ninjatrader.com/support/helpGuides/nt8/index.html?options_strategies.htm#Understandingnin jascriptProperties

        CancelFlatten() and SendStrategyTerminationAlert() are not documented NinjaScript methods in the help guide. Are these custom methods you have programmed?

        To simulate a forced disable of the strategy you would need to code your strategy logic to purposely hit an error. For example, submitting a stop loss order above the market or submitting a profit target order below the market.

        Regarding the error in the forum thread you shared, indexes must be a non-negative number and less than the size of the collection. The error may be indicating the index requested is larger than the number of elements in the collection. In the case of barsAgo values with Series, any barsAgo index must be less than CurrentBar (the total number of bars is the size of a Series collection).

        You could follow the advice shared by my colleague Chelsea on that forum thread to determine what line of code in the script is causing the index error.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          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 Thomas79, 01-23-2014, 10:14 AM
          10 responses
          1,504 views
          0 likes
          Last Post martin70  
          Started by istinethomas, Today, 03:31 AM
          0 responses
          7 views
          0 likes
          Last Post istinethomas  
          Started by joselube001, 05-10-2024, 12:17 PM
          7 responses
          49 views
          0 likes
          Last Post esatino
          by esatino
           
          Started by kevinenergy, 05-09-2024, 12:01 PM
          9 responses
          41 views
          0 likes
          Last Post jeronymite  
          Started by ETFVoyageur, Yesterday, 07:49 AM
          2 responses
          14 views
          0 likes
          Last Post jeronymite  
          Working...
          X