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

Exiting short and going long weird behavior

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

    Exiting short and going long weird behavior

    Hi,

    I'm doing something wrong, I just can't figure out what. I'm trying to do the following (in this order):

    1) Go short
    2) Exit short
    3) Go long

    When I get to the third step, I somehow end up with 2 contracts when I should only have one. Here's a more in-depth look at what I do for each step.

    1) Go short by calling EnterShort(1, "Tx"). By using TraceMode I get this:

    9/29/2009 10:05:58 AM Entered internal PlaceOrder() method at 9/29/2009 10:05:58 AM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Tx' FromEntrySignal=''
    9/29/2009 10:05:58 AM Entered internal PlaceOrder() method at 9/29/2009 10:05:58 AM: Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=66.32 SignalName='S-Tx' FromEntrySignal='Tx'

    From OnExecution when this order is filled I set a stop loss by calling ExitLong(0, true, execution.Order.Filled, LastStopPrice, "S-Tx", "Tx"). LastStopLoss is a value I calculate.

    2) From OnBarUpdate when some exit condition is met I call ExitShort("Tx") to exit the condition. TraceMode tells me this:

    9/29/2009 10:06:17 AM Entered internal PlaceOrder() method at 9/29/2009 10:06:17 AM: Action=BuyToCover OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='Tx'

    3) Right after #2 (I don't wait for a fill, maybe this is why...) I want to enter long by calling EnterLong(1, "Tx")

    9/29/2009 10:06:17 AM Entered internal PlaceOrder() method at 9/29/2009 10:06:17 AM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Tx' FromEntrySignal=''
    9/29/2009 10:06:17 AM Cancelled pending exit order, since associated position is closed: Order='e1f8ca889a40498182edfeef32c0d6e7/Replay101' Name='S-Tx' State=Accepted Instrument='CL 11-09' Action=BuyToCover Limit price=0 Stop price=66.32 Quantity=1 Strategy='PeterATR' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='e1f8ca889a40498182edfeef32c0d6e7' Gtd='12/1/2099 12:00:00 AM'

    So, any clue why I end up with 2 contracts instead of one?

    Thank you.

    #2
    pbz1111, please retry the same without the second step, using the Enter() methods would automatically reverse your position if needed. Also ensure you're synched up properly when testing this with live data and execution - http://www.ninjatrader-support.com/H...tPosition.html
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      pbz1111, please retry the same without the second step, using the Enter() methods would automatically reverse your position if needed. Also ensure you're synched up properly when testing this with live data and execution - http://www.ninjatrader-support.com/H...tPosition.html
      In some cases I can do that, i.e. I can directly go long rather than an exit the short and then a long. However, there are cases where I don't want to immediately go long, at least not at that second, but right after exiting a short, that the conditions to go long would be met and I would need to go long. In such cases I couldn't avoid a rapid succession of exit short, go long "commands." For case like this, what can I do to prevent the issue I'm seeing?

      On the link you provided:Reading through that article I came across this sentence: "You want to run multiple strategies in the same market simultaneously where strategy A holds a LONG 1 position, strategy B holds a LONG 2 position resulting in an account that should hold a LONG 3 position in order to be in sync with both strategies"

      Does this mean that we won't be able to run a strategy on one instrument and another strategy on a different instrument? What exactly does "same market" mean in this case? This would make sense if talking about the same instrument.

      Comment


        #4
        Same instrument is what it means.

        If you require rapid succession the only way to go about it is to wait for order confirmations on fills prior to submitting the EnterLong too.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Josh View Post
          Same instrument is what it means.

          If you require rapid succession the only way to go about it is to wait for order confirmations on fills prior to submitting the EnterLong too.
          OK... Sometimes I may need to place "rapid" (depends on the market) calls to ExitLongStop or ExitShortStop. Do I need to wait for these to be filled before placing a new one, or is it OK not to wait for a fill? Thanks.

          Comment


            #6
            Exit on Exit doesn't matter. The area you need to be careful about is when you try to go Exit and then Enter. If you need to go Enter after an Exit you should always wait for Exit fill confirmation before placing in the Enter.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Josh View Post
              Exit on Exit doesn't matter. The area you need to be careful about is when you try to go Exit and then Enter. If you need to go Enter after an Exit you should always wait for Exit fill confirmation before placing in the Enter.
              But, just to make sure, if I need to switch / reverse I can just call a long command when I'm short and vice versa and it would work without any fill waiting... (actually there's not much to wait for since it's a single command).

              Thanks Josh!

              Comment


                #8
                That would be correct.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Josh View Post
                  That would be correct.
                  Thanks Josh.

                  One more quick question and I'll shut up ( for today ). If I call a stop loss and before it gets filled I want to switch positions. On the "broker" side are these commands queued up? Would I still get the fill on the stop loss and then the reverse, or is there no way or knowing? Thanks.

                  Thanks again.

                  Comment


                    #10
                    No way of knowing. You could be filled on reverse, you could be filled on stop, you could be filled on both. You should only place one at a time when dealing with orders that will close the prior position.
                    Josh P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by stafe, 04-15-2024, 08:34 PM
                    7 responses
                    31 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by adeelshahzad, Today, 03:54 AM
                    4 responses
                    30 views
                    0 likes
                    Last Post adeelshahzad  
                    Started by merzo, 06-25-2023, 02:19 AM
                    10 responses
                    823 views
                    1 like
                    Last Post NinjaTrader_ChristopherJ  
                    Started by frankthearm, Today, 09:08 AM
                    5 responses
                    17 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by jeronymite, 04-12-2024, 04:26 PM
                    3 responses
                    43 views
                    0 likes
                    Last Post jeronymite  
                    Working...
                    X