Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

strategy and position not the same

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

    strategy and position not the same

    Hi,

    I recently had two positions open of 0.2M short in my programmed strategy. Then the strategy triggered the buy to cover (exit short) order for both of those 0.2M shorts when it was supposed to do so, and it opened a single 0.2M buy order which happened to be at the same point of the exit short order which it was supposed to.
    The problem is that the strategy also did a close position on the two open short positions in addition to the buy to cover. So instead of now being 0.2M long due to the single buy order, I am now 0.6 long because of the extraneous close position (or is it the buy to cover that was extraneous).
    But now even more confusing is that the position window is showing only 0.4 long even while the strategy window is showing the 0.6 long.
    Either way, it should really only be 0.2 long because it shouldn't have "close position" after it already "buy to cover" (see attachment).

    Please help me figure out how to stop my program from both buying to cover and closing position before it opens another position in the opposite direction.

    Thanks.
    Attached Files

    #2
    werido,

    This can happen when you use two competing orders to do the same thing at the same time. It can result in both getting filled and thus overfilling and resulting in unwanted positions.

    You should only have one order at a time. If you wanted to reverse, cancel any stop/limit order you may be using and do not submit an ExitShort(). Just submit your EnterLong() and it will automatically take care of the rest by closing your position and getting you long.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      My exit long order and exit short order are global to the whole strategy so I can't remove them. Is there a condition that I can put on them or on each of the individual entry orders to stop the duplicate fills?
      Does the order (1st 2nd 3rd, etc.) that the entry or exit orders appear in the C# code make a difference as to which comes first? I mean if the order is covered first, it wouldn't need to be closed to allow for the next entry order, or if the order is closed to allow for the next entry order, it wouldn't need to be covered by the exit order.
      How do I it from both being filled?

      Would assigning the exit orders to each entry order separately prevent the exit order from filling when the next entry order closes it out to fill it's own entry order?

      Thanks.
      Last edited by werido; 07-19-2010, 03:42 PM.

      Comment


        #4
        werido,

        No, you cannot have two competing orders or else you run this risk. NT does not know you closed your position at the point in time you submitted the order and as such it will try to close the position even if the buy-to-cover happens right before. This is what is meant by an overfill. You will need to program your strategy to only submit one order at a time. When conditions meet you need to cancel one and only use one at a time to eliminate this risk.

        I am not following you by your comment on filling its individual entry orders. When you call EnterLong() it can only go long when you are flat and as such all shorts need to be closed. You cannot call EnterLong() and have it ultimately still remain in a short position. It will go into a long position.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          There is no way to set a priority on the exit orders to come last, after the entry orders are all searched, so that the entry order would take care of the close position, and the exit order would have nothing to exit?

          Comment


            #6
            No, when orders are placed there is no controlling which one has priority over which other ones. Once orders are submitted they are off to the brokerage/exchange. Whatever happens at the brokerage/exchange will determine which one gets filled first. There is no guarantee one will happen before the other.

            The problem you run when you submit both is that you have both going into the market. When one gets filled it takes time for your brokerage to report this fill back to you. When NT does not receive that report back yet if the second order gets filled now too then you are stuck in the exact scenario you have shown in your first post. You get an overfill. NT had no chance to cancel the extra order because it was never reported to your NT that the first order was filled and the second order is now extra. You get both filled and are left with both an extra position.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              But this was all in sim101.
              If I'm using this strategy on a 10 min chart, would adjusting the entry orders, which for example are now set to execute only during 3:00am to 4:10am, to instead execute during 3:00:08am to 4:10:08, giving the exit orders 8 seconds time to execute before the entry orders do (once the chart advances 10 min and plots another bar)?
              No wait, that wouldn't work because the signal for exit and entry might be some time in the middle of that span of time.

              so is there no way to delay the execution of the entry orders (or exit orders by a few seconds)?

              Is there a delay code?

              Thanks
              Last edited by werido; 07-19-2010, 04:14 PM.

              Comment


                #8
                werido,

                You need to program your strategy in a fashion that eliminates the risk of overfills. This means not having competing orders. There is no way around this. Introducing delays and such just reduces the risk, but does not eliminate the risk.

                The only procedure I can recommend is only submitting one order to achieve the exit at a time. If you end up wanting to use the other one later on, cancel the first and submit the second after the first is confirmed canceled.

                Furthermore you really don't need both orders since they are doing the same thing. If you are simply trying to reverse from short to long there is never a reason why you would need to ExitShort() before just reversing.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  the reason I have the exit in the program is because most of the time the indicators reach the exit signal and there is no entry signal reached. But some times, the exit signal IS the entry signal if other factors are met at that time. These orders are all market orders. Its automated so I'd like to let it run and execute properly.
                  I just realized that changing the time won't delay the execution (even if I divide up the code to apply to every 10 minutes separately on the 10 minute chart) because the time is just a condition for execution, but once the bar changes, the codes immediately execute.
                  Unless, is there a delay code?

                  Thanks again.

                  Comment


                    #10
                    werido,

                    What you can do is use OnExecution() then. When your exit order fills then submit your entry order after that fact for the times when you want to enter the market in the opposite direction.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      how do I use OnExecution() ?

                      Comment


                        #12
                        Please see an example here: http://www.ninjatrader.com/support/f...ead.php?t=7499

                        When your exit order is filled and your conditions are met for entering into a new position, place the new entry order method call into OnExecution().
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          If I place the exits of my strategy in a separate strategy, will the exits execute based on the fact there is an open position from the first strategy that is also on the same chart, or will those exits in the separate strategy only execute if there is an open position in that same strategy (in which case the strategy with only exits will never execute)?
                          Thank you.

                          Comment


                            #14
                            The later, separate strategies do not know the positions of any other strategy and will not be able to manage them.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              With regards to the double fill ( "buy to cover"(exit short) --- and "close position"(before entering long) -- as in the attached image) there seems to be a discrepancy between the backtesting and live trading.
                              In backtesting, the strategy executes in the order of the commands listed in it and is aware of every step it took before moving on to the next step so that if, for example, the same tick calls for selling short as well as exit short, the backtest will do both knowing that it had first sold short.
                              Whereas in the live trading, the strategy will do the sell short but will not see that it just sold short in order to exit that short. So the exit command will not execute.
                              Is that correct? That in backtesting, the strategy will eliminate this double fill problem, but in live trading, the strategy will not acknowledge that it just executed a step and take that into consideration when executing the next step?
                              Last edited by werido; 08-05-2010, 02:02 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by usazencort, Today, 01:16 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post usazencort  
                              Started by kaywai, 09-01-2023, 08:44 PM
                              5 responses
                              603 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by xiinteractive, 04-09-2024, 08:08 AM
                              6 responses
                              22 views
                              0 likes
                              Last Post xiinteractive  
                              Started by Pattontje, Yesterday, 02:10 PM
                              2 responses
                              21 views
                              0 likes
                              Last Post Pattontje  
                              Started by flybuzz, 04-21-2024, 04:07 PM
                              17 responses
                              230 views
                              0 likes
                              Last Post TradingLoss  
                              Working...
                              X