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

Reverse position & auto close previous

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

    Reverse position & auto close previous

    When I reverse position then NT's Internal Order Handling mechanism automaticaly closes my current position @ new position's entry price.

    How can I close my current position @ another price, for example @ bar's open price?

    These are limit orders.
    Last edited by Argo1; 09-12-2009, 05:31 AM.

    #2
    Hello,

    Are you talking about backtesting or in a live environment?

    Post your code so I see what you are doing currently.
    I'm not 100% sure what you are want and what is happening.
    DenNinjaTrader Customer Service

    Comment


      #3
      Backtesting. 1 day bars. Forex market.
      I'm no longer using limit orders but stop orders.

      In brief:
      How to push NT to close long stop position at market price, not at entry price for reversal position, when reversing?


      Example:

      Day 1:
      I went long with EnterLongStop() method. Stop price=156.98. NT State=Filled. - That's OK.

      Day 2:
      There is a signal fo reversing position (from today's close price).
      1) I try to open short position with EnterShortStop() method. Stop price=155.87. Output window:
      2000-11-28 00:00:00 Entered internal PlaceOrder() method at 2000-11-28 00:00:00: Action=SellShort OrderType=Stop Quantity=0,1M LimitPrice=0 StopPrice=155,87 SignalName='MyEntryShort' FromEntrySignal=''

      2) NT automatically tries to close my long position:
      2000-11-28 00:00:00 OnOrderUpdate(): Order='NT-00011/Back101' Name='Close position' State=PendingSubmit Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=155,87 Quantity=0,1M Strategy='X' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token=

      3) Close position's order is not going to "Filled" state because today is no market price for this:
      Prices for this day bar: O:156.73 H:157.14 L:155.96 C:156.07
      Stop price for close position is: 155.87.

      Day 3:
      Today close long order and open short stop order are cancelled because of expiration.
      Prices for this day bar: O:157.28 H:160.74 L:157.23 C:160.43


      What I want to have is that NT could close my long position at market price, not at stop price from new short order when I reverse market position.
      Long position should be closed at open price for day 3.
      Last edited by Argo1; 09-13-2009, 11:19 AM.

      Comment


        #4
        Hello,

        Why don't you use ExitLong(), which uses a market sell order? Then enter in the other direction. The internal reversal logic that comes into play when you try to go both ways in the market is not something you can change. It is hard coded in the orders.
        DenNinjaTrader Customer Service

        Comment


          #5
          I tried ExitLong() before, but it doesn't work well:
          It closes long at day 3. open price - this is good, but it does not opens short position after this.
          I put ExitLong() in OnBarUpdate(). Maybe I should put it elsewhere?

          Comment


            #6
            This is log for this "reversal" day:

            Code:
            Cancelled custom managed order at 2000-11-28 00:00:00: Order='NT-00009/Back101' Name='MyTargetLong' State=Working Instrument='$GBPJPY' Action=Sell Limit price=159,98 Stop price=0 Quantity=0,1M Strategy='X' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='02cf63bf921841819c803a6e43e64e15' Gtd='2099-12-01 00:00:00'
            2000-11-28 00:00:00 Entered internal PlaceOrder() method at 2000-11-28 00:00:00: Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
            2000-11-28 00:00:00 Entered internal PlaceOrder() method at 2000-11-28 00:00:00: Action=SellShort OrderType=Stop Quantity=0,1M LimitPrice=0 StopPrice=155,87 SignalName='MyEntryShort' FromEntrySignal=''
            2000-11-28 00:00:00 OnOrderUpdate(): Order='NT-00009/Back101' Name='MyTargetLong' State=PendingCancel Instrument='$GBPJPY' Action=Sell Limit price=159,98 Stop price=0 Quantity=0,1M Strategy='X' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='02cf63bf921841819c803a6e43e64e15' Gtd='2099-12-01 00:00:00'
            2000-11-28 00:00:00 OnOrderUpdate(): Order='NT-00009/Back101' Name='MyTargetLong' State=Cancelled Instrument='$GBPJPY' Action=Sell Limit price=159,98 Stop price=0 Quantity=0,1M Strategy='X' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='02cf63bf921841819c803a6e43e64e15' Gtd='2099-12-01 00:00:00'
            2000-11-28 00:00:00 OnOrderUpdate(): Order='NT-00010/Back101' Name='Sell' State=PendingSubmit Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=0 Quantity=0 Strategy='X' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='4d7ce5d907e64efaa81bb4455143af21' Gtd='2099-12-01 00:00:00'
            2000-11-28 00:00:00 OnOrderUpdate(): Order='NT-00010/Back101' Name='Sell' State=Accepted Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=0 Quantity=0 Strategy='X' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='4d7ce5d907e64efaa81bb4455143af21' Gtd='2099-12-01 00:00:00'
            2000-11-28 00:00:00 OnOrderUpdate(): Order='NT-00010/Back101' Name='Sell' State=Working Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=0 Quantity=0 Strategy='X' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='4d7ce5d907e64efaa81bb4455143af21' Gtd='2099-12-01 00:00:00'
            2000-11-28 00:00:00 OnOrderUpdate(): Order='NT-00010/Back101' Name='Sell' State=Filled Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=0 Quantity=0,1M Strategy='X' Type=Market Tif=Gtc Oco='' Filled=100000 Fill price=156,14 Token='4d7ce5d907e64efaa81bb4455143af21' Gtd='2099-12-01 00:00:00'
            2000-11-28 00:00:00 OnExecution(): Execution='NT-00007' Instrument='$GBPJPY' Account='Back101' Name='Sell' Exchange=Default Price=156,14 Quantity=0,1M Market position=Short Commission=0 Order='NT-00010' Time='2000-11-29 00:00:00' Multiplier=1E-05
            2000-11-28 00:00:00 OnPositionUpdate(): Instrument='$GBPJPY' Account='Back101' Avg price=0 Quantity=0 Market position=Flat


            There is "Entered internal PlaceOrder() method at 2000-11-28 00:00:00: Action=SellShort" but nothing more this day nor next day.
            Last edited by Argo1; 09-13-2009, 12:35 PM.

            Comment


              #7
              Is it possible that NT can't process these two orders: ExitLong() and EnterShortStop() on the same bar?
              Last edited by Argo1; 09-13-2009, 11:57 AM.

              Comment


                #8
                Hello,

                Are you backtesting? If so, everything is done on bar close. Also the code iterates in OnBarUpdate() only when an new bar comes in/closes. This may be what is causing the issue for you.
                DenNinjaTrader Customer Service

                Comment


                  #9
                  It is backtesting on daily bars. There are bars after day 3.
                  Normally, when I reverse position using only EnterShortStop() method (without ExitLong()) then NT automatically closes long and opens short on the same bar.
                  NT disallows
                  manual execution both ExitLong() and EnterShortStop() orders on the same bar?

                  Comment


                    #10
                    Argo1,

                    That is correct. In backtesting this happens because it does not realize these were actually placed in the same bar to go together. You will need to use the Enter() directly to get the reversal on the same bar.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks, Josh.

                      Thus, answer for my post #1 question is: it's impossible ?

                      Comment


                        #12
                        Correct. From a backtesting scenario that would be the case.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Ok, thank you.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by cre8able, Today, 09:15 PM
                          0 responses
                          1 view
                          0 likes
                          Last Post cre8able  
                          Started by cummish, Today, 08:43 PM
                          0 responses
                          6 views
                          0 likes
                          Last Post cummish
                          by cummish
                           
                          Started by Option Whisperer, Today, 07:58 PM
                          4 responses
                          18 views
                          0 likes
                          Last Post Option Whisperer  
                          Started by ETFVoyageur, 05-07-2024, 07:05 PM
                          13 responses
                          86 views
                          0 likes
                          Last Post ETFVoyageur  
                          Started by cupir2, Today, 07:44 PM
                          0 responses
                          11 views
                          0 likes
                          Last Post cupir2
                          by cupir2
                           
                          Working...
                          X