Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

8.0.3.1 - OnExecutionUpdate Called Multiple Times w/ OrderState.Filled

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

    8.0.3.1 - OnExecutionUpdate Called Multiple Times w/ OrderState.Filled

    Hi,

    I haven't really used NT8 for live trading (in this case for a paper account) so I'm not sure if this is expected behaviour, but I really don't think it should be since I'm doing exactly the same thing in NT7.

    So here's the code I have for OnExecutionUpdate:

    Code:
    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    	Print ("A");
    
    	if (execution.Order.OrderState == OrderState.Filled)
    	{
    		Print ("B");
    		SendEmail();
    	}
    }
    The strategy submits a market order (e.g. EnterLong/ExitLong/EnterShort/ExitShort). Based on the size, this order is usually broken up into smaller lots which each count as a separate trade which should trigger OnExecutionUpdate. Therefore I would expect to see "A" printed several times. However, for each market order, there should only be one execution which fills the order, thus I would expect to see only one "B" and only one e-mail.

    What I'm seeing though, is that "B" seems to get printed a variable number of times (and I'm also receiving the accompanying emails). Since the e-mails sent to me contain execution.Order.ToString(), I can confirm that it is the same orderId being "completely filled" multiple times. For five orders my strategies submitted today, I received:
    3x triples
    1x double
    1x single (which is what it should be)

    In case it matters, I'm enabling my strategies from the strategy grid rather than from a chart.

    Thanks for the help.
    Last edited by wuileng; 02-01-2017, 08:31 AM.

    #2
    Do you have small toy strategy that demonstrates the behavior?

    Comment


      #3
      Hello wuileng,

      Thank you for the post.

      With just the description and example code I am unsure what could be the problem. As bltdavid asked we would likely need some sort of sample along with the output you had seen from that sample to know what may be happening. If you have a sample you can provide that demonstrates this, it would be helpful. Otherwise if you can provide the total code you use in OnExecutionUpdate along with the output you had seen that may be able to help as well.

      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #4
        That code in my original post is really all there is in my OnExecutionUpdate but I have come up with a sample strategy anyways. In the sample strategy, you will need to modify the SendMail line and put in a correct recipient e-mail.

        Don't run it on the NT Sim101 account as I believe it might give you a single fill for the whole order. I believe the problem occurs when you do live trading or live paper trading when the fills you get for an order might be split into two or three (or more) smaller fills. Please see my attached screenshot to see what I mean by this: both the stacks of buys and sells there were generated by a single order.

        This is what I expect to see from running my strategy. Two instances of "A" because the order was filled in two fills, however only the second fill should really trigger "B" because on the first fill, the order state should not yet have been fully filled:
        Code:
        A
        A
        B = orderId='1690651207' account='DU139922' name='Buy' orderState=Filled instrument='VXX' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=2,000 tif=Gtc oco='' filled=2000 averageFillPrice=19.8 onBehalfOf='' id=126 time='2017-01-24 14:40:23' gtd='2099-12-01' statementDate='2017-01-24'
        Email - Message sent successfully
        However, this is what I am getting:
        Code:
        A
        B = orderId='1690651207' account='DU139922' name='Buy' orderState=Filled instrument='VXX' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=2,000 tif=Gtc oco='' filled=2000 averageFillPrice=19.8 onBehalfOf='' id=126 time='2017-01-24 14:40:23' gtd='2099-12-01' statementDate='2017-01-24'
        A
        B = orderId='1690651207' account='DU139922' name='Buy' orderState=Filled instrument='VXX' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=2,000 tif=Gtc oco='' filled=2000 averageFillPrice=19.8 onBehalfOf='' id=126 time='2017-01-24 14:40:23' gtd='2099-12-01' statementDate='2017-01-24'
        Email - Message sent successfully
        Email - Message sent successfully
        Note that it is the same orderId which is triggering the inner loop, meaning that the same orderId is fully filled twice - which really shouldn't be the case.
        Attached Files

        Comment


          #5
          Hello wuileng,

          I tried this using a paper account rather than the sim101 account but was unable to see the same outcome. Could you tell me what connection are you currently using? Also is this a paper or live account being used?

          For my test I used an IB paper account and recieved the following output, I had also appended the order state to the Print for clarity:

          Code:
          if(execution.Order != null)
          {
          	Print ("A : " + execution.Order.OrderState.ToString());
          	
          	if (execution.Order.OrderState == OrderState.Filled)
          	{
          		Print ("B = " + execution.Order.ToString());
          	}
          }

          A : PartFilled
          A : PartFilled
          A : PartFilled
          A : PartFilled
          A : PartFilled
          A : PartFilled
          A : PartFilled
          A : PartFilled
          A : PartFilled
          A : PartFilled
          A : PartFilled
          A : PartFilled
          A : PartFilled
          A : PartFilled
          A : PartFilled
          A : PartFilled
          A : PartFilled
          A : PartFilled
          A : PartFilled
          A : Filled
          B = orderId='9c9fb26273294fdf9fec0f5769eeab22' account='Sim101' name='Buy' orderState=Filled instrument='VXX' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=2,000 tif=Gtc oco='' filled=2000 averageFillPrice=19.34963 onBehalfOf='' id=65 time='2017-01-26 09:19:20' gtd='2099-12-01' statementDate='2017-01-26'
          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Hi,

            I'm experiencing this on an IB paper account (prefix DU). I could also test it on a live account (prefix U) but would rather not since this problem does affect some of my strategy's internal tracking logic and I have the feeling it is linked to the multiple fills per order (hence I'd be unable to test using a 1 share order).

            However, although you said you tested it with an IB paper account, I see from your quote that the account name is Sim101?

            Comment


              #7
              Hello,

              I am sorry that was from another test, I had tested on a DU prefix account and received the same result.

              Can you tell me are you using the current supported version of TWS listed here? http://ninjatrader.com/ConnectionGui...nnection-Guide

              NT8 recently had changed its supported version to 960.2g, if you are using a different version this could potential be a reason for this.

              Please let me know if I may be of additional assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Thanks, let me have a look into that, and I'll get back to you with my findings after potentially updating my TWS/IB Gateway.

                Comment


                  #9
                  Modified my code so A displays the state as well. I also updated to TWS and IB Gateway 960.2g using the versions available through your link on the NT site.

                  What I found was that around the market open, it worked fine for 2,000 shares, but at other random times during the day (such as a few minutes ago and for 5,000 shares) - I still encountered the problem.

                  AFilled
                  B = orderId='248169269' account='DU139922' name='Buy' orderState=Filled instrument='VXX' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=5,000 tif=Gtc oco='' filled=5000 averageFillPrice=19.12 onBehalfOf='' id=158 time='2017-01-27 11:10:01' gtd='2099-12-01' statementDate='2017-01-27'
                  AFilled
                  B = orderId='248169269' account='DU139922' name='Buy' orderState=Filled instrument='VXX' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=5,000 tif=Gtc oco='' filled=5000 averageFillPrice=19.12 onBehalfOf='' id=158 time='2017-01-27 11:10:01' gtd='2099-12-01' statementDate='2017-01-27'
                  AFilled
                  B = orderId='248169269' account='DU139922' name='Buy' orderState=Filled instrument='VXX' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=5,000 tif=Gtc oco='' filled=5000 averageFillPrice=19.12 onBehalfOf='' id=158 time='2017-01-27 11:10:01' gtd='2099-12-01' statementDate='2017-01-27'
                  AFilled
                  B = orderId='248169269' account='DU139922' name='Buy' orderState=Filled instrument='VXX' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=5,000 tif=Gtc oco='' filled=5000 averageFillPrice=19.12 onBehalfOf='' id=158 time='2017-01-27 11:10:01' gtd='2099-12-01' statementDate='2017-01-27'
                  Email - Message sent successfully
                  Email - Message sent successfully
                  Email - Message sent successfully
                  Email - Message sent successfully
                  On a second test:

                  APartFilled
                  AFilled
                  B = orderId='248169296' account='DU139922' name='Buy' orderState=Filled instrument='VXX' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=5,000 tif=Gtc oco='' filled=5000 averageFillPrice=19.07 onBehalfOf='' id=160 time='2017-01-27 11:22:24' gtd='2099-12-01' statementDate='2017-01-27'
                  AFilled
                  B = orderId='248169296' account='DU139922' name='Buy' orderState=Filled instrument='VXX' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=5,000 tif=Gtc oco='' filled=5000 averageFillPrice=19.07 onBehalfOf='' id=160 time='2017-01-27 11:22:24' gtd='2099-12-01' statementDate='2017-01-27'
                  AFilled
                  B = orderId='248169296' account='DU139922' name='Buy' orderState=Filled instrument='VXX' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=5,000 tif=Gtc oco='' filled=5000 averageFillPrice=19.07 onBehalfOf='' id=160 time='2017-01-27 11:22:24' gtd='2099-12-01' statementDate='2017-01-27'
                  Email - Message sent successfully
                  Email - Message sent successfully
                  Email - Message sent successfully
                  Last edited by wuileng; 01-27-2017, 10:25 AM.

                  Comment


                    #10
                    Hello wuileng,

                    Thank you for the reply and updating.

                    Being that this is random I will need to continue to test to see if I get the same result. I will continue to test our paper account to see if I can replicate this, once I have further details I will report them back here.

                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      I got another multiple when the strategy flattened at the close.

                      Could it be because I'm using IB Gateway instead of TWS? If that might be the cause, I could test it next week.

                      Comment


                        #12
                        Hello wuileng,

                        Yes this certainly could be the difference between our testing. I had previously been testing using TWS, if you are using gateway instead that could be it. I will need to retest this during the week to see if I am able to confirm the same as you are. If you could test using the TWS client as well that would be helpful.

                        I look forward to being of further assistance.
                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          Still seeing the same thing really. The first test is done on TWS 960.2g and the second on IB Gateway 960.2g. The Java version I'm using is v8-121.

                          Do you have any idea what else could be the problem? Can no one else replicate this?

                          It's doubtful, but it wouldn't be because of my IB (Paper) Account or the fact that I'm running Windows 7 would it?

                          Enabling NinjaScript strategy 'SampleOnExecutionUpdate/91529536' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=By strategy position ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Keep running DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=True CancelExitsOnStrategyDisable=True Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
                          AFilled
                          B = orderId='1021344615' account='DU139922' name='Buy' orderState=Filled instrument='VXX' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=5,000 tif=Gtc oco='' filled=5000 averageFillPrice=19.97 onBehalfOf='' id=173 time='2017-01-30 13:27:02' gtd='2099-12-01' statementDate='2017-01-30'
                          AFilled
                          B = orderId='1021344615' account='DU139922' name='Buy' orderState=Filled instrument='VXX' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=5,000 tif=Gtc oco='' filled=5000 averageFillPrice=19.97 onBehalfOf='' id=173 time='2017-01-30 13:27:02' gtd='2099-12-01' statementDate='2017-01-30'
                          AFilled
                          B = orderId='1021344615' account='DU139922' name='Buy' orderState=Filled instrument='VXX' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=5,000 tif=Gtc oco='' filled=5000 averageFillPrice=19.97 onBehalfOf='' id=173 time='2017-01-30 13:27:02' gtd='2099-12-01' statementDate='2017-01-30'
                          Email - Message sent successfully
                          Email - Message sent successfully
                          Email - Message sent successfully
                          Disabling NinjaScript strategy 'SampleOnExecutionUpdate/91529536'

                          Enabling NinjaScript strategy 'SampleOnExecutionUpdate/91529536' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=By strategy position ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Keep running DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=True CancelExitsOnStrategyDisable=True Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
                          AFilled
                          B = orderId='1021344616' account='DU139922' name='Buy' orderState=Filled instrument='VXX' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=5,000 tif=Gtc oco='' filled=5000 averageFillPrice=19.94 onBehalfOf='' id=174 time='2017-01-30 13:29:05' gtd='2099-12-01' statementDate='2017-01-30'
                          AFilled
                          B = orderId='1021344616' account='DU139922' name='Buy' orderState=Filled instrument='VXX' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=5,000 tif=Gtc oco='' filled=5000 averageFillPrice=19.94 onBehalfOf='' id=174 time='2017-01-30 13:29:05' gtd='2099-12-01' statementDate='2017-01-30'
                          AFilled
                          B = orderId='1021344616' account='DU139922' name='Buy' orderState=Filled instrument='VXX' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=5,000 tif=Gtc oco='' filled=5000 averageFillPrice=19.94 onBehalfOf='' id=174 time='2017-01-30 13:29:05' gtd='2099-12-01' statementDate='2017-01-30'
                          Email - Message sent successfully
                          Email - Message sent successfully
                          Email - Message sent successfully

                          Comment


                            #14
                            Hello wuileng,

                            Thank you for your response.

                            I cannot say if it is due to the account type or not, but I would not suspect the Operating System in this case.

                            We will follow up with you when we have further details.

                            Comment


                              #15
                              Thanks, tried with 8.0.4. and still getting the same problem.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by wftrrdt, Today, 05:01 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post wftrrdt
                              by wftrrdt
                               
                              Started by wellbeingcbd, Today, 04:41 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post wellbeingcbd  
                              Started by piydasuknu, Today, 03:45 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post piydasuknu  
                              Started by ajdfkgjiojjhfihjg, Today, 03:20 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post ajdfkgjiojjhfihjg  
                              Started by keravitahere, Today, 01:56 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post keravitahere  
                              Working...
                              X