Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simulate Partial fill ... with ease.

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

    Simulate Partial fill ... with ease.

    (Please read Post ... I have more details)

    First three questions:
    #1
    When a reversing order is placed it consists of two orders ... one to close the open position and another to reverse ... when I check the state of the order using the IOrder object which order am I referencing the closing position or the order to establish a new position?

    #2
    When the orders are sent to the market the order to close the open position seems to be sent/placed/accepted first and does arrive first ... I know this is true is this what was intented?

    #3
    If question #2 = true then how do you suggest I reference the order that is in the market which will establish the new position?

    I am coding something and need to deal with GTC orders that have partial fills and need to be canceled since I need to place a new "fresh" order at another price level.

    This problem seems to always happen with partial fills ... and I need to debug.

    By problem I mean I try to cancel the order and it is not canceled ... I need to debug this problem in development

    I have been having problems with the below sample code:
    Code:
    [SIZE=2][FONT=Courier New][COLOR=#008000]//only cancel the order if it was part filled ... or this is not the hour for trading any longer.[/COLOR][/FONT][/SIZE]
    [FONT=Courier New][SIZE=2][COLOR=#008000]//So if we are still Long ... thats good we can easily modify the order qty.[/COLOR][/SIZE][/FONT]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (ShortOrderObj != [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (ShortOrderObj.OrderState == OrderState.PartFilled || (Position.MarketPosition == MarketPosition.Long && !TradeThisHour() && LastContractsToTrade != HourMaskedQty))[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (Position.MarketPosition == MarketPosition.Long && !TradeThisHour() && LastContractsToTrade != HourMaskedQty)[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]LastContractsToTrade = HourMaskedQty;[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
     
    [SIZE=2][FONT=Courier New]CancelOrder(ShortOrderObj);[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]ShortOrderObj = [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]; [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]//Release handle on that order.[/COLOR][/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]}[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    Later in the code I place the order again like such:
    Code:
    [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#008000]//If we are using EndDate then we need to check if we are beyond the LastDayOfTrading[/COLOR][/SIZE][/FONT]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (UseEndDate && EndDate < Time[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]])[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]ShortOrderObj = ExitLongLimit([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], LastContractsToTrade, ShortOrderPrice , [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"ExitLastLong"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"GoLong"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]{[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]ShortOrderObj = EnterShortLimit([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], LastContractsToTrade, ShortOrderPrice , [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"GoShort"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    [/SIZE][/FONT]
    This is really hard to debug without being able to reproduce the problem. In real life I have no problems getting partial fills on orders for Euro futures of 20 or more contracts or US 30 year T-bonds ... happens allot ... then the price action moves away from my partially filled order and I want to act.

    So is there a way to reproduce the following using simulated connection or otherwise?
    Partial fill of order ... then have price action move away and not completely fill the remaining outstanding order. I tried starting the strategy for 100+ contracts and selected the enforce partial fills in options, that did not work ... nothing did.
    I played with the trend ... moved it up and down ... quickly reversing trend just as the price got close ... it still filled all the way, frustrating.

    I need to debug this but do not want to debug in production or use one account to buy from another account to "simulate" my problem in production in some lightly traded thing.

    Any suggestions?


    (I did just find out that orders sent to the exchange are issued exchnage order IDs that are not in the order in which they were submitted to the exchange ... it seems that the broker sends both orders and the closing order was accepted second even though the closing order was given a brokder order # smaller than the order number for the order to establish a new position) -- not sure who to talk to about that.

    -Lars
    Last edited by ltemme; 08-15-2008, 05:47 PM. Reason: Added two questions on top.

    #2
    Sorry, what exactly is your issue?

    Note: You always could simulate life trading e.g. on the Sim101 account using any feed. This would show you how it all works.

    Comment


      #3
      My issue .. explained step by step.

      Did you read all of my post ...?
      I find it hard to believe that you did not understand the "issue" since I even had questions at the top of the post that were sure to answer my core questions regarding my "issue".

      Please answer those first, then read further to appreciate why I am asking the questions I am asking.

      (I did just find out that orders sent to the exchange are issued exchnage order IDs that are not in the order in which they were submitted to the exchange ... it seems that the broker sends both orders and the closing order was accepted second even though the closing order was given a brokder order # smaller than the order number for the order to establish a new position) -- not sure who to talk to about that.
      Here is a step by step scenario of my "issue"

      I am long 20 contracts.
      I place an order to reverse that position and go short 1 contract. I do issue the method call entershortlimit and set the output to an IOrder object.
      The NT platform breaks that order into two seperate orders.
      One order is named "Close Position" for 20 contracts the other is named "GoShort", the name I gave it, for 1 contract. These two orders are sent to the marketplace. The order named "GoShort" is filled first ... 1 contract, that's out of the way fine. The order named "Close Position is still there with 20 contracts ... some of those are filled as well but eventually the price action moves away and I would very much like to cancel that order ... I have problems doing so. I believe that the IOrder object state is Filled ... not partially filled since the "Close Position" order was intented to fill first and the logic is that is the "GoShort" order is filled the "Close Position" order must be filled since that order was placed first.

      I think that I have a race condition where even though the "Close Position" order is placed first it get posted to the exchange second on occasion. and the IOrder object shows orderstate of filled.

      Hope that clears things up.

      -Lars

      Comment


        #4
        You could try under Tools > Options> Simulator enabled "Enforce partia fills". The close order should be sent before the GOSHORT order. Can you very that this is the case the next time by reviewing the Control Center log tab, you should see the close order be submitted first.
        RayNinjaTrader Customer Service

        Comment


          #5
          On the order ID issue, you would need to contacy your broker.
          RayNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by cmtjoancolmenero, Yesterday, 03:58 PM
          4 responses
          23 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Brevo, Today, 01:45 AM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by rjbtrade1, 11-30-2023, 04:38 PM
          2 responses
          73 views
          0 likes
          Last Post DavidHP
          by DavidHP
           
          Started by suroot, 04-10-2017, 02:18 AM
          5 responses
          3,021 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by Stanfillirenfro, Today, 07:23 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X