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

Strange Market Order Partial Fill Exit Behavior

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

    Strange Market Order Partial Fill Exit Behavior

    Hey guys.

    I seem to have a reoccurring problem with my market exit orders acting strange. Here is some information on my strategy.

    - The strategy is End of Bar. There is no OnMarketData() call or something else that is done intrabar that will allow multiple entry / exit function calls.
    - I do not use setstop / settarget methods provided by NT.
    - Entries and exits are limited to only once per bar.

    In the OnBarUpdate() method I have the following logical structure.

    The Entrance Logic
    Code:
    if(Position.MarketPosition == MarketPosition.Flat)
    {
        if(Conditions true to go long)
          {
              EnterLong(vQuantity, "enterLongGood");
              return;
          }
        if(Conditions true to go short)
          {
              EnterShort(vQuantity, "enterShortGood");
              return;
          }
    }
    The Exit Logic
    Code:
    if(Position.MarketPosition == MarketPosition.Long)
    {
        if(Conditions true to exit Long)
          {
              ExitLong("ExitLongBreakEven", "enterLongGood");
              return;
          }
    }
    if(Position.MarketPosition == MarketPosition.Short)
     {
         if(Conditions true to exit Short)
           {
               ExitShort("ExitShortBreakEven", "enterShortGood");
               return;
           }
     }
    In one case I have a partially exited fill. According to the log file relevant in part,
    // ENTER
    8/29/2008 6:45:48 AM|1|32|Order='16e3db5a-acctName-b/x1234567' Name='enterShortGood' New State=PendingSubmit Instrument='$EURUSD' Action=SellShort Limit price=0 Stop price=0 Quantity=0.1M Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
    8/29/2008 6:45:48 AM|1|32|Order='1150201:05ph/x1234567' Name='enterShortGood' New State=Accepted Instrument='$EURUSD' Action=SellShort Limit price=0 Stop price=0 Quantity=0.1M Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
    8/29/2008 6:45:48 AM|1|32|Order='1150201:05ph/x1234567' Name='enterShortGood' New State=Working Instrument='$EURUSD' Action=SellShort Limit price=0 Stop price=0 Quantity=0.1M Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
    8/29/2008 6:45:49 AM|1|64|Instrument='$EURUSD' Account='x1234567' Avg price=1.47271 Quantity=0.1M Market position=Short Operation=Insert Currency=UsDollar
    8/29/2008 6:45:49 AM|1|32|Order='1150201:05ph/x1234567' Name='enterShortGood' New State=Filled Instrument='$EURUSD' Action=SellShort Limit price=0 Stop price=0 Quantity=0.1M Type=Market Filled=100000 Fill price=1.47271 Error=NoError Native error=''
    8/29/2008 6:45:49 AM|1|16|Execution='NT_20080829_0045' Instrument='$EURUSD' Account='x1234567' Exchange=Default Price=1.47271 Quantity=0.1M Market position=Short Operation=Insert Order='1150201:05ph' Time='8/29/2008 6:45:49 AM' Multiplier=1E-05


    // EXIT
    8/29/2008 7:31:36 AM|1|32|Order='16e3db5a-acctName-c/x1234567' Name='ExitShortBreakEven' New State=PendingSubmit Instrument='$EURUSD' Action=BuyToCover Limit price=0 Stop price=0 Quantity=0.1M Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
    8/29/2008 7:31:36 AM|1|32|Order='1150201:061l/x1234567' Name='ExitShortBreakEven' New State=Accepted Instrument='$EURUSD' Action=BuyToCover Limit price=0 Stop price=0 Quantity=0.1M Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
    8/29/2008 7:31:36 AM|1|32|Order='1150201:061l/x1234567' Name='ExitShortBreakEven' New State=Working Instrument='$EURUSD' Action=BuyToCover Limit price=0 Stop price=0 Quantity=0.1M Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
    8/29/2008 7:31:37 AM|1|64|Instrument='$EURUSD' Account='x1234567' Avg price=1.47271 Quantity=0.09M Market position=Short Operation=Update Currency=UsDollar

    8/29/2008 7:31:37 AM|1|32|Order='1150201:061l/x1234567' Name='ExitShortBreakEven' New State=PartFilled Instrument='$EURUSD' Action=BuyToCover Limit price=0 Stop price=0 Quantity=0.01M Type=Market Filled=10000 Fill price=1.4731 Error=NoError Native error=''
    8/29/2008 7:31:37 AM|1|16|Execution='NT_20080829_0049' Instrument='$EURUSD' Account='x1234567' Exchange=Default Price=1.4731 Quantity=0.01M Market position=Long Operation=Insert Order='1150201:061l' Time='8/29/2008 7:31:37 AM' Multiplier=1E-05
    8/29/2008 7:31:37 AM|1|32|Order='1150201:061l/x1234567' Name='ExitShortBreakEven' New State=PendingChange Instrument='$EURUSD' Action=BuyToCover Limit price=0 Stop price=0 Quantity=0.09M Type=Market Filled=10000 Fill price=1.4731 Error=NoError Native error=''
    8/29/2008 7:31:37 AM|1|64|Instrument='$EURUSD' Account='x1234567' Avg price=1.47271 Quantity=0.07M Market position=Short Operation=Update Currency=UsDollar

    8/29/2008 7:31:37 AM|1|32|Order='1150201:061l/x1234567' Name='ExitShortBreakEven' New State=PartFilled Instrument='$EURUSD' Action=BuyToCover Limit price=0 Stop price=0 Quantity=0.02M Type=Market Filled=30000 Fill price=1.4731 Error=NoError Native error=''
    8/29/2008 7:31:37 AM|1|16|Execution='NT_20080829_0050' Instrument='$EURUSD' Account='x1234567' Exchange=Default Price=1.4731 Quantity=0.02M Market position=Long Operation=Insert Order='1150201:061l' Time='8/29/2008 7:31:37 AM' Multiplier=1E-05
    8/29/2008 7:31:37 AM|1|32|Order='1150201:061l/x1234567' Name='ExitShortBreakEven' New State=PendingChange Instrument='$EURUSD' Action=BuyToCover Limit price=0 Stop price=0 Quantity=0.07M Type=Market Filled=30000 Fill price=1.4731 Error=NoError Native error=''
    8/29/2008 7:31:37 AM|1|64|Instrument='$EURUSD' Account='x1234567' Avg price=1.47271 Quantity=0.07M Market position=Short Operation=Remove Currency=UsDollar

    8/29/2008 7:31:37 AM|1|32|Order='1150201:061l/x1234567' Name='ExitShortBreakEven' New State=Filled Instrument='$EURUSD' Action=BuyToCover Limit price=0 Stop price=0 Quantity=0.07M Type=Market Filled=100000 Fill price=1.4731 Error=NoError Native error=''
    8/29/2008 7:31:37 AM|1|16|Execution='NT_20080829_0051' Instrument='$EURUSD' Account='x1234567' Exchange=Default Price=1.4731 Quantity=0.07M Market position=Long Operation=Insert Order='1150201:061l' Time='8/29/2008 7:31:37 AM' Multiplier=1E-05

    8/29/2008 7:31:37 AM|1|32|Order='1150201:061l/x1234567' Name='ExitShortBreakEven' New State=PendingChange Instrument='$EURUSD' Action=BuyToCover Limit price=0 Stop price=0 Quantity=0.07M Type=Market Filled=30000 Fill price=1.4731 Error=UnableToChangeOrder Native error=' Replace rejected for reason: No such order'
    8/29/2008 7:31:37 AM|0|32| Replace rejected for reason: No such order Affected Order: BuyToCover 70000 Market
    8/29/2008 7:31:37 AM|1|32|Order='1150201:061l/x1234567' Name='ExitShortBreakEven' New State=Filled Instrument='$EURUSD' Action=BuyToCover Limit price=0 Stop price=0 Quantity=0.07M Type=Market Filled=100000 Fill price=1.4731 Error=UnableToChangeOrder Native error=' Replace rejected for reason: No such order'
    8/29/2008 7:31:37 AM|0|32| Replace rejected for reason: No such order Affected Order: BuyToCover 70000 Market
    You can see the entrance is executed and filled fine, the exit order is broken into a few partially filled orders. The exit order was completely filled but there are Rejected Orders. I am questioning whether NT handles this properly, as this has happened a few times and has occasionally left me with a partial position that the strategy "forgets about."

    The OnBarUpdate() was only executed ONCE for this exit order; the next bar time was at 7:45:11AM, so I don't believe its a multiple ExitShort() function call by my NT code.

    Any ideas?

    Thanks.
    mrlogik
    NinjaTrader Ecosystem Vendor - Purelogik Trading

    #2
    Partial fills can occur from a single order and order rejections can happen for any reason. You should program some backup checks to ensure you are not left with unwanted positions.

    I suggest you run additional checks after you place your exit order to ensure you have truly closed out of your position.
    Josh P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Jonker, 04-27-2024, 01:19 PM
    3 responses
    23 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by businessman1929, 04-29-2024, 01:28 PM
    2 responses
    21 views
    0 likes
    Last Post businessman1929  
    Started by bltdavid, 03-27-2023, 05:32 AM
    18 responses
    347 views
    0 likes
    Last Post ETFVoyageur  
    Started by NM_eFe, Today, 05:15 PM
    0 responses
    5 views
    0 likes
    Last Post NM_eFe
    by NM_eFe
     
    Started by vitaly_p, Today, 05:09 PM
    0 responses
    6 views
    0 likes
    Last Post vitaly_p  
    Working...
    X