Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit exact position.

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

    Exit exact position.

    Hello.
    In a managed strategy I placed the first sell market order and it was filled at a price 1000. Then I placed the second sell market order and it was filled at 1050. How can I exit positions generated only by the second order?
    Last edited by n0_namer; 09-12-2013, 03:02 PM.

    #2
    Hello,

    Thanks for your post.

    You can exit a specific order by using signal names.

    For example:
    EnterLong("myLong1");
    EnterLong("myLong2");

    ExitLong("myLong1", "myExitSignal1");

    Please see the Using multiple entry/exit signals simultaneously reference sample for an example of this.
    http://www.ninjatrader.com/support/f...ead.php?t=3225

    Also, please see the help guide on ExitLong().
    http://www.ninjatrader.com/support/h...7/exitlong.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I'm using signal names. Look at screen below. When I use ExitLong with fromEntrySignal "ENT2" it closes ENT0 enter instead ENT2.

      Comment


        #4
        Hello n0_namer,

        May I see the code you are using to submit the orders?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Code for Enter:
          Code:
          EnterShort(0, contrNum1, "ENT"+i);
          EnterShort(1, contrNum2,  "ENT"+i);
          Code for Exit:
          Code:
                                      if (Positions[0].MarketPosition == MarketPosition.Long)
                                          tmpO = ExitLong(0, lstCntrNum1[i], "EXT"+i.ToString(), "ENT"+i.ToString());
                                      if (Positions[0].MarketPosition == MarketPosition.Short)
                                          tmpO = ExitShort(0, lstCntrNum1[i], "EXT"+i.ToString(), "ENT"+i.ToString());
                                      
                                      lstExtOrd1.Add(tmpO);
                                      
                                      if (Positions[1].MarketPosition == MarketPosition.Long)
                                          tmpO = ExitLong(1, lstCntrNum2[i], "EXT"+i, "ENT"+i);
                                      if (Positions[1].MarketPosition == MarketPosition.Short)
                                          tmpO = ExitShort(1, lstCntrNum2[i], "EXT"+i, "ENT"+i);
          
                                      lstExtOrd2.Add(tmpO);
          May be NT using FIFO during replay? http://www.ninjatrader.com/support/f....php?p=341404#
          Last edited by n0_namer; 09-15-2013, 07:40 AM.

          Comment


            #6
            Hello n0_namer,

            Thank you for you response.

            NinjaTrader does in fact use FIFO for Market Replay as well as simulation and real-time trading. However, with your code you are using two different bars in progress indexes and exiting the positions of these individual indexes. This should work, the only item I can see form the snipet of code you provided is that I do not know how the 'i' variable is defined and how this differs for each bars in progress index.

            Can you perhaps provide the full code or a toy version of the strategy that I can test this matter on my end with?

            I look forward to assisting you further.

            Comment


              #7
              I need some time to make a toy strategy. It is easier for me to ask your a few more questions.

              NinjaTrader does in fact use FIFO for Market Replay as well as simulation and real-time trading.
              NT using FIFO on real account too? After i've read this post http://www.ninjatrader.com/support/f....php?p=341404# i thought there is not FIFO on real.

              However, with your code you are using two different bars in progress indexes and exiting the positions of these individual indexes
              I use two bars in progress for two instruments, that I use in my strategy. There can be several enters for each instrument in same direction.

              I need LIFO in my strategy, how can i realize it in NT?

              Comment


                #8
                Hello n0_namer,

                The ordering system for a live broker is different from broker to broker.

                Some brokers, such as CQG do use FIFO.

                I recommend that you contact your broker and inquire about this.

                Regarding last in, first out, you would need to have logic in your code to handle this.

                For example you could track the orders using an integer. Then submit exit orders using the integer number.

                Attached is an example of this.
                Attached Files
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello, ChelseaB.
                  For example you could track the orders using an integer
                  I'm doing the same thing in my strategy.

                  I've raplayed you example and got the same result:

                  FIFO

                  Comment


                    #10
                    Hello n0_namer,

                    Thank you for your reply.

                    After talking with our development department I have found that the Account Performance report does not pair trades by signal name in the report. Instead these are reported with FIFO.

                    However, the order logic with a strategy will pair the orders by signal name and will exit the proper order.

                    To demonstrate this I have modified the script I provided. The script now enters different amounts for each order, 1 for the first, 2 for the second, and 4 for the third. I have also placed a text box on the screen that shows the current position amount after each order is made or exited.

                    What happens using this is the last order with a quantity of 4 is exited first leaving the position with 3. Then the second order is exited leaving the position at 1. Then the last order is exited.

                    Please let me know if you have questions with the modifications.
                    Attached Files
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello.
                      Can you look at my modification of your strategy? In my mod I calculate unrealized PnL by myself and compare it with NT UPnL got by GetProfitLoss function. Before exit orders are filled PnLs are equal, but after first exit order are not. Is unrealized PnL in NT calculated using FIFO too? Will this repeat at real account?
                      P.S.: sorry for my english )
                      Attached Files

                      Comment


                        #12
                        Hello,

                        In your code you are dynamically setting IOrder objects to an array list. This does not really work. While it will save a copy of the object to the array, this is no longer the IOrder object that NinjaTrader is processing.

                        I would recommend that you do not save the IOrder objects to an array list.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello, ChelseaB.
                          I need only AvgPrice of orders to count PnL. The questions I'am interested in is in which way calculated unrealized PnL in NT, FIFO or LIFO?

                          Comment


                            #14
                            Hello n0_namer,

                            I wanted to let you know I am seeing the issue and am working with our development department to get a proper answer together for you.

                            The issue I am finding is that your calculated avgFillPrice is not equal to Position.AvgPrice.

                            This is a tick or two off causing the profit to be incorrect.

                            I am still working on this and will be with you in a short while.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hello n0_namer,

                              Thanks for your patience as I continued looking into this.

                              I would like you to enable the following option and then try testing your script again.
                              • Click Tools -> Options... -> check the box for Use FIFO for position avg. price calculations


                              Please let me know if this does not correct the issue.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by TraderBCL, Today, 04:38 AM
                              2 responses
                              16 views
                              0 likes
                              Last Post TraderBCL  
                              Started by martin70, 03-24-2023, 04:58 AM
                              14 responses
                              106 views
                              0 likes
                              Last Post martin70  
                              Started by Radano, 06-10-2021, 01:40 AM
                              19 responses
                              609 views
                              0 likes
                              Last Post Radano
                              by Radano
                               
                              Started by KenneGaray, Today, 03:48 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post KenneGaray  
                              Started by thanajo, 05-04-2021, 02:11 AM
                              4 responses
                              471 views
                              0 likes
                              Last Post tradingnasdaqprueba  
                              Working...
                              X