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:
[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]
[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]
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
Comment