Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop order state?

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

    Stop order state?

    I must be doing something wrong with automated trading still... because I just saw the price on a stock fall right through a stop order that I thought had been placed.

    I then looked back, and realized maybe the stop order never went live.

    I have launched my strategy, and it sets a stop loss price at $11. On the "orders" tab, it shows state (in orange) as "pendingsubmit". Why wouldn't it be live? The orders tab shows this:

    MAC Sell Stop 1,000 0 11.00 PendingSubmit 0 0 1,000 Stop loss NT-00002 Day ...xxxx.... TD iZone NT-00003 ProtectDown 98a5e5b9cc83441fae868a484addc7b9 11/24/2008 11:15:55 AM + - X

    What does PendingSubmit mean? Why isn't it working?

    #2
    Pretty damn scary. It looks like this is a known problem that others have had, and doesn't seem to ever have resolved. Stop orders can silently disappear...?

    Support for the development of custom automated trading strategies using NinjaScript.


    How useful is this platform if I can't rely on stops to be processed? Why isn't there a timeout at least on pending submit, after which it's automatically canceled? Only solution I can think of is putting in OnOrderUpdate() code which will watch for stop orders "stuck" in pending submit... and cancel/replace after a few minutes.

    Comment


      #3
      I closed everything, restarted (with a different instrument that should have a live stop order)... and exact same problem:

      HOG Sell Stop 800 0 13.13 PendingSubmit 0 0 800 Stop loss NT-00000 Day xxxxxxx TD iZone NT-00001 ProtectDown 8718bf44953c4a05b2c08cca1aca957c 11/24/2008 11:43:07 AM + - X

      What am I missing? I know buy orders have been successfully placed. Why are stop orders going missing?

      UPDATE: I turned on "traceorders", and it doesn't give any insight. It only says this:

      11/24/2008 11:30:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Price Value=13.125 Currency=0 Simulated=False

      My "onorderupdate" call then fires with a "PendingSubmit" notification. Nothing else to add. I hope someone can get back to me with a solution for this issue soon.
      Last edited by heech; 11-24-2008, 01:55 PM.

      Comment


        #4
        I have confirmed that I can place a working Sell Stop order by hand, through the trading panel on the orders tab.

        Comment


          #5
          heech,

          You are going to need to post code and your trace logs for us to evaluate the situation. The link you provided was most likely long resolved since there have been many version updates since then. You are likely having a separate concern.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            What "trace logs"? Are you referring to output print from TraceOrders (which I linked below), or something else?

            Comment


              #7
              I do not see any link below, only snippets. Yes, the TraceOrders logs as well as the logs available in My Documents\NinjaTrader 6.5\log. Please also include the timestamp as to when the issue was encountered.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Should I email you the trace logs... or? I'm not comfortable sharing the code in its entirety, but there's really nothing executing here other than SetStopLoss(), after I entered a position enternally. If you need to see dummy code, I can generate a stripped down version tomorrow when markets open again.

                Here's the relevant portions of the trace logs, unmodified:

                11/24/2008 10:04:24 AM|1|32|Order='4494011036/707028387' Name='External' New State=Filled Instrument='HOG' Action=Buy Limit price=0 Stop price=0 Quantity=800 Type=Market Filled=800 Fill price=14.1175 Error=NoError Native error=''
                11/24/2008 10:04:24 AM|1|16|Execution='4494011818' Instrument='HOG' Account='707028387' Exchange=Default Price=14.1175 Quantity=800 Market position=Long Operation=Insert Order='4494011036' Time='11/24/2008 10:04:24 AM'
                11/24/2008 10:04:24 AM|1|64|Instrument='HOG' Account='707028387' Avg price=14.1175 Quantity=800 Market position=Long Operation=Insert Currency=UsDollar
                11/24/2008 10:07:05 AM|1|128|Starting NinjaScript strategy 'ProtectDown/3067559d8c104e21beb1adc81842bcca' : On starting a real-time strategy - StrategySync=SubmitLive EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=ByStrategyPosition ErrorHandling=TakeNoAction ExitOnClose=False Set order quantity by=Strategy
                11/24/2008 10:07:32 AM|1|128|Starting NinjaScript strategy 'ProtectDown/d88ff22855504ef08361c1e291528b5d' : On starting a real-time strategy - StrategySync=SubmitLive EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=ByStrategyPosition ErrorHandling=TakeNoAction ExitOnClose=False Set order quantity by=Strategy
                11/24/2008 11:09:42 AM|1|128|Starting NinjaScript strategy 'ProtectDown/a8391d25314c4ceca57b753f7de3e4f2' : On starting a real-time strategy - StrategySync=SubmitLive EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=ByStrategyPosition ErrorHandling=TakeNoAction ExitOnClose=False Set order quantity by=Strategy
                11/24/2008 11:09:42 AM|1|32|Order='NT-00001/707028387' Name='Stop loss' New State=PendingSubmit Instrument='HOG' Action=Sell Limit price=0 Stop price=13.13 Quantity=800 Type=Stop Filled=0 Fill price=0 Error=NoError Native error=''
                No other mention of symbol HOG and the PendingSubmit order, until I start canceling/tweaking things by hand in a failed attempt to get things working.

                As mentioned above, I entered into the position manually. Oh wait a second... is *that* the problem?

                I just realized that with SetStopLoss(), stop orders are only generated when an entry order is filled... presumably within the strategy. But what I'm doing is entering my position first externally, so there's no stop order. I *then* start my strategy, thinking it will be able to pick itself up... but perhaps it's getting stuck trying to cancel a previous (non-existent) stop order before submitting itself?

                Apologies for wasting your your time Josh. I could erase the discussion above since I suspect I Know the answer, but I'll leave it up in case others run into a similar issue.

                Anyways, if this is the case, if I'm potentially restarting the strategy at an arbitrary point in the execution... then my fix is perhaps to get rid of SetStopLoss(), and use ExitLongStop() every time? I assume that ExitLongStop() will be wise enough to replace an existing stop order, if one exists?

                Or... what would you suggest?

                Comment


                  #9
                  heech,

                  Stripped down version would work just fine. You can email me directly if you do not wish to post it here. josh [dot] peng [at] ninjatrader [dot] com.

                  In terms of starting your strategy afterwards. Strategies do not pick up anything from "before". It will maintain its own Strategy Position and this can be very different than your Account Position. Please see this article: http://www.ninjatrader-support2.com/...ead.php?t=4033
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Josh View Post
                    heech,

                    Stripped down version would work just fine. You can email me directly if you do not wish to post it here. josh [dot] peng [at] ninjatrader [dot] com.

                    In terms of starting your strategy afterwards. Strategies do not pick up anything from "before". It will maintain its own Strategy Position and this can be very different than your Account Position. Please see this article: http://www.ninjatrader-support2.com/...ead.php?t=4033
                    Josh,

                    I understand the definition (and difference) between Strategy/Account position. My question is about the difference in behavior between SetStopLoss() versus ExitLongStop(), and how they behave upon a "restart".

                    The manuals aren't clear on this, but my best guess (that I'd like you to address):

                    - SetStopLoss() only enters a new stop order when a live EnterLong() order is processed. Otherwise, it only tries to cancel an existing stop order and submit a new stop order in its place. If there is no existing stop order, it gets stuck in PendingSubmit.

                    - On the other hand, ExitLongStop() will always cancel any existing stop orders, and regardless of whether any exist... put in a new stop order at the specified price.

                    Comment


                      #11
                      There is no "restart" logic. Neither of them will pick up anything from any prior run of the strategy.

                      All of those are based off of what the strategy thinks its position is. No manual trades or any prior strategy instance trades have impact on them. Only trades from the current instance of the strategy.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        I'm still not sure what's going on. I'll try to duplicate something for you tomorrow.

                        Alternatively, I think I'm going to try to get around this by using simulated stop orders... but it's not clear to me from the docs whether simulated stop orders are available in conjunction with NinjaScript strategy. Can you confirm? Do I enable it using Tools->Options, ATI Tab?

                        Comment


                          #13
                          Simulated stop orders are available in NinjaScript. http://www.ninjatrader-support.com/H...tStopLoss.html

                          You can see there is a signature with a simulated bool.

                          I believe we are not on the same page. NinjaScript Strategies do not retrieve anything from previous runs. If you stop your strategy and start it again all trades and things like that do not persist. The strategy will go through all the historical bars and recalculate out what it thinks its strategy position is. From there it determines if you will have a stop loss in place or not. This stop loss will either be a live order or another virtual order depending on settings you have set in Tools->Options->Strategies->NinjaScript. If you select "Wait until flat before executing live" this order will be a virtual order. Most people like to use this setting because it allows for the easiest syncing with their account position. All you have to do is make sure your account position is flat before starting your strategy. Now when your strategy starts it will wait until it is flat before placing live trades. When it is ready to make a live trade it will now be in sync with the account position.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by NinjaTrader_Josh View Post
                            I believe we are not on the same page. NinjaScript Strategies do not retrieve anything from previous runs. If you stop your strategy and start it again all trades and things like that do not persist. The strategy will go through all the historical bars and recalculate out what it thinks its strategy position is.
                            Yes, I fully understand this part.

                            From there it determines if you will have a stop loss in place or not. This stop loss will either be a live order or another virtual order depending on settings you have set in Tools->Options->Strategies->NinjaScript. If you select "Wait until flat before executing live" this order will be a virtual order. Most people like to use this setting because it allows for the easiest syncing with their account position. All you have to do is make sure your account position is flat before starting your strategy. Now when your strategy starts it will wait until it is flat before placing live trades. When it is ready to make a live trade it will now be in sync with the account position.
                            I absolutely don't want to use wait until flat, and that option is disabled. I trade live immediately. I'm trading a multi-day (multi-week actually_ strategy, and I want to be able to stop/restart my strategy without having to flatten everything every time.

                            The issue still lies with the stop orders, which simply have never registered. The only angle that I have to go on is the fact I acquired these positions externally, rather than using NT. NT *shouldn't* care as long as the positions match... and when I look at the chart, I can see the "hypothetical" buys that have occurred historically from the strategy point of view. It all looks correct up to the point where it places a "sell stop" order at the price I set, except the stop order is never active/working.

                            So, again, I believe I fully understand the intended behavior of the system. It is simply not working that way, and I'll try to duplicate after market open.

                            Comment


                              #15
                              heech,

                              That is fine if you don't want to use Wait until flat, but you need to understand that there is NO restart logic. If you stop your strategy that is it. It is the end of the line. When you start it again there is no recovery of anything.

                              NT does NO position matching with your account. All manual orders have no bearing on your strategy and your strategy will not care about them.

                              When you start up a strategy it calculates out a strategy position. Let us say it starts up and it decides it is long. If the strategy would have been long with some stop/limit order active at this point in time those orders will be submitted live. If there are none the strategy will just wait for your closing logic and then just close the position.
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by stafe, Yesterday, 08:34 PM
                              1 response
                              15 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by jclose, Yesterday, 09:37 PM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by firefoxforum12, Yesterday, 08:53 PM
                              1 response
                              15 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by kmunroe478, Yesterday, 05:39 PM
                              2 responses
                              15 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by kevinenergy, 02-17-2023, 12:42 PM
                              115 responses
                              2,700 views
                              1 like
                              Last Post kevinenergy  
                              Working...
                              X