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

RealTimeErrorHandling with code exceptions

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

    RealTimeErrorHandling with code exceptions

    Hello,

    I am detecting abnormal behaviors in a strategy, and I would like to resolve a question: if the RealTimeErrorHandling property is set to StopCancelClose and an exception occurs in the code (for example of type NullReferenceException) what should happen? I assume that pending orders (Accepted, Working) are automatically canceled, the open position is closed if any, and the strategy is also deactivated. It is right?
    (The checkboxes in Tools/Options/Properties/Strategies/NinjaScript : "Cancel entry orders when a strategy is disabled" & "Cancel exit orders when a strategy is disabled" are checked).
    Thanks

    #2
    Hello cls71,

    Thank you for your post.

    Yes, if an error occurs in the strategy, any pending orders will be cancelled if you have those boxes in the options checked, it will attempt to close the position (if the error is due to a disconnect, it would not be successful), and the strategy is disabled.

    Here's a link to our help guide that goes over this property:



    Please let us know if we may be of further assistance to you.


    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thanks Kate,

      but it seems that it is not working like this. I have attached a simple testing strategy to check it out.

      This strategy sends a Buy Mar****rder to enter Long. When the order fill is received in the OnExecutionUpdate method, two exit orders (stoploss + takeprofit) are sent. Then in the OnPositionUpdate method, when the message that the position is Long is received, an error is forced in the code which raises an Exception.
      Automatic Error Handling cancels OCO orders and deactivates the strategy. But it does not send a closing order to close the position.
      Attached Files

      Comment


        #4
        Hello cls71,

        Thank you for your note.

        It looks like your issue likely stems from the fact that you're never resetting the orderEntry variable. Here's an example script from a different forum post that uses the unmanaged approach for orders and demonstrates properly resetting your order objects. You're also not assigning your stop loss and profit target to an order object at all, so you have no way to track those and this demonstrates how to do this as well.

        https://ninjatrader.com/support/foru...579#post770579

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Thanks Kate,

          I am sorry, but your answer has nothing to do with the issue I have posted. Are you sure you understand the issue I have and the code I have attached ? Maybe I have not explained myself clearly, sorry.

          The issue is that after an error or exception the system does not close the position automatically. The RealTimeErrorHandling property is set to StopCancelClose and according to the documentation, the open position should automatically close.

          The exit bracket orders have nothing to do with it. I was just using it to check that live orders are automatically canceled when there is an error or exception.
          I send you the test code again without sending the bracket. And you will see that the error is the same => the position stays open after an exception.

          You just have to execute the strategy to check that an exception is raised, then the strategy is disabled but the position remains open without closing.

          Thanks
          Attached Files

          Comment


            #6
            Hello cls71,

            Thank you for your note.

            Ah, thank you for your clarification. I'm seeing the same with your revised strategy - your original version didn't place the order at all for me.

            I've reached out to our development team for clarification on whether it would be expected for a strategy to simply disable without performing StopCancelClose behavior on runtime errors and will let you know what they say.

            Thanks in advance; I look forward to assisting you further.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Hello cls71,

              Thank you for your patience.

              I've heard back from the development team, and it appears it would be expected for the strategy to invoke StopCancelClose behavior on order Rejections from the exchange, it would not be expected to invoke this behavior on a run time error.

              I have created a feature request on your behalf to expand StopCancelClose to perform this behavior on a run time error. This request is being tracked under the number SFT-4854.

              As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted in the Release Notes page of the Help Guide.

              Release Notes — https://ninjatrader.com/support/help...ease_notes.htm

              Please let us know if we may be of further assistance to you.
              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Please add my vote for SFT-4854. Automatically closing a Strategy and associated trade positions if there is a run-time software error makes sense. However, the existing default functionality to invoke StopCancelClose behavior on a mere order Rejection from an exchange is ridiculous. Occasional, and in fast markets even frequent, exchange order rejections are a normal aspect of trading. Shutting down an automatically trading Strategy merely because prices are moving quickly is financially risky and idiotic. Furthermore, NinjaTrader shouldn't be making trading decisions for users (is the company licensed to do that?). If users want to stop trading in fast markets they can design that into their trading logic, but NinjaTrader shouldn't cause trading losses or the loss of fast-market trading opportunities either by closing market positions or unnecessarily shutting down automatic trading software that users are relying upon for trading decisions.
                Last edited by caveat_lector; 11-09-2020, 11:38 AM.

                Comment


                  #9
                  Hello caveat_lector,

                  Thank you for your feedback.

                  I have added a vote for you to SFT-4854 as well.

                  As usual, if implemented it will be mentioned in the Release Notes here:

                  Release Notes — https://ninjatrader.com/support/help...ease_notes.htm

                  Please let us know if we may be of further assistance to you.
                  Kate W.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi, please add my vote for SFT-4854 to, tanks.
                    sidlercom80
                    NinjaTrader Ecosystem Vendor - Sidi Trading

                    Comment


                      #11
                      Hello sidlercom80,

                      Thank you for your reply.

                      I've added a vote for you to SFT-4854 as well.

                      Please let us know if we may be of further assistance to you.
                      Kate W.NinjaTrader Customer Service

                      Comment


                        #12
                        I realize this is quite old but I would add a vote for this feature. If it hasn't otherwise been featured or processed. I have been having to build multiple systems to monitor the status of the application, the strategy, the connection, and computer and effectively close the position.

                        How is this not a bigger problem or are there other threads on comprehensive systems?

                        Thanks in advanced.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by rocketman7, Today, 02:12 AM
                        5 responses
                        23 views
                        0 likes
                        Last Post rocketman7  
                        Started by trilliantrader, 04-18-2024, 08:16 AM
                        7 responses
                        28 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Started by samish18, 04-17-2024, 08:57 AM
                        17 responses
                        66 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Started by briansaul, Today, 05:31 AM
                        1 response
                        15 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Started by PaulMohn, Today, 03:49 AM
                        1 response
                        12 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Working...
                        X