Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy error processing behavior for open positions

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

    Strategy error processing behavior for open positions

    I'm working on a strategy that uses non-time based bars, and if there is an issue where many bars prints at once, the strategy can error out. No problem, it happens. But what is odd is that there are times that even though the working orders are canceled (stop loss and profit target), there is still a position open with no working orders to handle the position. This obviously has some fairly interesting implications if you're not watching the screen.

    Is this normal behavior? Or should the position be flattened if there is an error? If this is normal, how can I modify the strategy to flatten the position if there is an error?

    How about when the connection is lost? Should that cancel the strategy and flatten the position?

    Thanks

    #2
    Hello sclay115,

    An open position just means the strategy didn't close the position. If the stop and target are cancelled that does not mean the position will be closed. That sounds like normal behaviour, your script needs to close the position if it opened it.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello sclay115,

      An open position just means the strategy didn't close the position. If the stop and target are cancelled that does not mean the position will be closed. That sounds like normal behaviour, your script needs to close the position if it opened it.
      Is there any way to build the position closing into the error processing?

      Comment


        #4
        Hello sclay115,

        if the reason is for a disconnect then no, you wouldn't be connected to the server to close the position. You would have to manually close the position once reconnected.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello sclay115,

          if the reason is for a disconnect then no, you wouldn't be connected to the server to close the position. You would have to manually close the position once reconnected.

          Okay, then how about for a strategy that errors out? Is there a way to automatically close all positions in the instrument the strategy is/was running in?

          Comment


            #6
            You can code your strategy around catching errors, but you would have to make sure you are catching them all, and just have the strategy handle what you want it to do. I would probably try to find out what the error is and resolve that. What error are you getting when things are happening too quickly?

            Comment


              #7
              Originally posted by rockmanx00 View Post
              You can code your strategy around catching errors, but you would have to make sure you are catching them all, and just have the strategy handle what you want it to do. I would probably try to find out what the error is and resolve that. What error are you getting when things are happening too quickly?
              It's a classic stop order on the wrong side of market price kind of error. Basically, what is happening in some cases is that when say the stop order is moved towards the current price for whatever reason in the strategy, the price shoots onto the other side of the stop before it can set. The strategy still tried to submit the stop, then errors out. It's only an issue with the non-time based bars. Tick, Renko, others? Since basically you can have a large number of them print almost instantly if prices move quickly.

              Comment


                #8
                Hello sclay115,

                For a stop being placed on the wrong side of the market we always suggest to approach that problem directly rather than trying to handle errors in the script. If the script is making invalid orders that would be easiest to correct by changing the offset being used or how the order is submitted. If you add rejection handling you will need to account for all errors as rockmanx00 mentioned so it would become a more complex script by doing that. If you want to look into that you can see the following page. https://developer.ninjatrader.com/do...eerrorhandling
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Jesse View Post
                  Hello sclay115,

                  For a stop being placed on the wrong side of the market we always suggest to approach that problem directly rather than trying to handle errors in the script. If the script is making invalid orders that would be easiest to correct by changing the offset being used or how the order is submitted. If you add rejection handling you will need to account for all errors as rockmanx00 mentioned so it would become a more complex script by doing that. If you want to look into that you can see the following page. https://developer.ninjatrader.com/do...eerrorhandling
                  I 100% agree, but there doesn't seem to be any solution that has been presented for when multiple non-time based bars print at the same time. I'm not sure if this is coming down to computing speed, latency, or strategy issues.

                  Here is a screenshot of where an error occurred. Can you please review the timestamps and recommend what to do in this situation?

                  Click image for larger version

Name:	image.png
Views:	36
Size:	22.3 KB
ID:	1334495

                  With all of those bars printing in the same minute, on the same second, the only order that was able to be submitted accurately was the position entry, however, as soon as it attempted to enter the stop order, the price was already below the attempted stop entry price.

                  Is this helpful for explaining the issue? ​

                  Comment


                    #10
                    Hello sclay115,

                    The rejection is very specific, at the time you submitted the order the price that was used was on the wrong side of the market. Changing the offset would be the first step to make sure its far enough away from the active market to avoid that. The frequency you call the method also matters, if you are calling this once per bar it could be called quickly with renko bars when many bars are generated so the update could be frequent. That also allows for this to happen if the order is close to the active market and the price changes direction quickly.


                    JesseNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Pointtoni, Yesterday, 11:41 PM
                    3 responses
                    24 views
                    0 likes
                    Last Post jenacie.com  
                    Started by DayTradingDEMON, Yesterday, 02:10 PM
                    5 responses
                    29 views
                    0 likes
                    Last Post DayTradingDEMON  
                    Started by Nate G, 03-17-2025, 02:53 PM
                    4 responses
                    59 views
                    1 like
                    Last Post timko
                    by timko
                     
                    Started by several, 03-18-2025, 03:53 AM
                    11 responses
                    175 views
                    1 like
                    Last Post timko
                    by timko
                     
                    Started by Amelie4262, Today, 10:45 AM
                    0 responses
                    10 views
                    0 likes
                    Last Post Amelie4262  
                    Working...
                    X