Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Incorrect Order Size on Close

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

    Incorrect Order Size on Close

    I'm running a strategy on market replay that closes trades at market price at 4:00PM EST. Order quantity is specified in the ExitLong() and ExitShort() functions (i.e., at 10 contracts). However, on some days, the strategy will submit an order to close out only 5 or 8 contracts, leaving an open position into overnight trading. This strategy is synchronized with my account position, and order quantity is set "by strategy." All entry signals are tied to unique exit signals (although the problem remains unsolved with a blanket ExitLong and ExitShort signal). Interestingly, during backtesting, the strategy always appears to submit orders to close out the entire position at the correct quantity. Any ideas as to why this might be happening? Thank you.

    #2
    drkempus, when you say you're synched up account / strategy position wise, do you check also during the progress of the strategy if the correct sync is maintained as you replay? It sounds to me you lose it at some point and then it does not match up in closing.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Bertrand, how can I tell if synchronization is lost during replay? For instance, at 3:00PM, the strategy opens at limit (and fully fills) an order for 10 contracts, but then closes out only 8 contracts at 4:00PM. Was sync lost between 3:00PM and 4:00PM? If so, is there any way to automatically correct for this, instead of manually placing an order for 2 contracts? It seems that a huge benefit of automated trading is taken away if the strategy cannot automatically maintain/re-establish sync, and incorrect position sizes are being executed.

      Comment


        #4
        drkempus, you would need to monitor the account vs strategy position then in your replay (same as in sim or live trading) to determine if and where you would loose proper syncing between those. For example was it completely flat (the account position) before the strategy bought the 10 lot at 3 PM?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          No, it was not completely flat before 3PM, but the positions in the control center (orders tab) matched up with the positions on the chart. In fact, up to the close, the positions in the control center matched up with those on the chart. The only difference I can tell is that when a limit order to execute 10 contracts would be generated by the strategy, the control center would should show one limit order at 10 contracts whereas the chart would show sometimes show several smaller orders equaling to 10 contracts (e.g., on a limit order to buy 10 contracts, the chart would sometimes show a limit order to buy 8 contracts and another limit order to buy 2 contracts, both generated and filled at the same time). In one particular instance, when these two separate orders to buy 8 contracts and 2 contracts were filled, the exitshort() generated a sell order for only 8 contracts, leaving an open position of 2 contracts. It should be noted that if the ninjascript is reloaded to the chart data, the two separate orders to buy 8 and 2 contracts would be replaced by one buy order for 10 contracts. Any ideas as to why this is happening?

          Thanks again, in advance, for your help.

          Comment


            #6
            drkempus, can you please check what OrderHandling setting you would use if you setup your strategy?

            BertrandNinjaTrader Customer Service

            Comment


              #7
              Bertrand, stop and target submission was on "per entry execution," although switching to "by strategy position" did not resolve the issue. Both "cancel entry orders when a strategy is disabled" and "cancel exit orders when a strategy is disabled" are checked.

              However, just to follow up, there indeed appears to be a sync problem. Whenever I reload the ninjascript EOD, an order is automatically generated (titled "synchronize") which closes any open positions, correctly rendering me flat. This order is generated even though there is no discrepancy in the total order sizes between the account and strategy positions. I have a feeling that the problem may be caused by the strategy executing several orders less than 10 contracts on the chart (by the way, I don't know what's causing the strategy to execute as several smaller orders on the chart). Any ideas? Thanks for your patience.

              Comment


                #8
                drkempus,

                Are you using NT7?

                Syncing orders to bring account positions to match strategy positions is highly dependent on what you have selected in terms of WaitUntilFlat or ImmediatelySubmit in Tools>Options>Strategies>NinjaScript.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  I think I may have found the problem. The executions tabs is doing something strange. Although it is correctly tracking my overall position size in the "position" column, some entries are being marked either as "exit" or "exit/entry". In the one instance where my order to buy 10 contracts was executed as two buy orders of 8 and 2 contracts, the order for 8 contracts was marked as an "entry" but the order for 2 contracts was marked as an "exit" (again, both were marked as "buy" in the "Action" column). Subsequently, the strategy only closed out 8 contracts EOD, presumably because only the previous transaction included an entry marked for only 8 contracts. Can you explain why the execution tab is marking these entries as exits or exit/entry? Thanks again.

                  Comment


                    #10
                    drkempus, could you please let us know if you're using WaitUntilFlat or Immdediately Submit as options to start the strategy under Tools > Options > Strategies > NinjaScript?

                    This still sounds like a sync issue to me from your descriptions - is the strategy reversing on the signals?

                    Would you see the same on our SampleMaCrossOver strategy in Replay?

                    When you start the strategy up on the replay day, is it historically flat if you check in the Strategies tab or would it carry over a position from the prior session?
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Bertrand and Josh, thank you very much for your help. I resolved the issue by switching to unmanaged mode and recoding my entries. One more question: with a TT data feed and the purchase of a license, will the chart show overnight data? I will not be holding overnight positions, but overnight price values need to be displayed on the chart for my indicators to function properly at market open. Right now, without a license, I only see current intraday data being displayed on the chart, even though overnight data is available through the "orders" tab of the control center.

                      Thanks again for your help and patience.

                      Comment


                        #12
                        You're welcome - since you're working with NT7, what session templates is your chart using? Are you sure you selected one that would include the overnight / ETH trading hours at all?
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Yes, I'm using the "Default 24/7" template. Unfortunately, it only shows data back to 6:10am EST of the given trading day. I need data from at least 1:00am EST of the given trading day. Note that if I download replay data for a given day, under the market replay connection, I get continuous chart data, from 12:00AM to 12:00AM, under the same template.

                          Comment


                            #14
                            Which realtime connection are you using right now in your testing?
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              I'm using a TT data feed through Velocity Futures.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by StrongLikeBull, Yesterday, 04:05 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by Mestor, 03-10-2023, 01:50 AM
                              14 responses
                              375 views
                              0 likes
                              Last Post z.franck  
                              Started by molecool, 10-09-2017, 10:48 AM
                              5 responses
                              1,621 views
                              0 likes
                              Last Post trader-ap  
                              Started by The_Sec, Yesterday, 03:53 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by mmenigma, Yesterday, 03:25 PM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X