I'm trying to detect the Part-Filled event on the TP-Order to Force exit it if it remains on Part-Filled situation after x Seconds;
By:
- Canceling it, then
- Submitting a Limit order on the nearest BID containing the remaining orders
The Question: How to get accurate (Simulated) Orders Filling/Part-Filling to study the accuracy of my code ?
Below is the simplified code and a Screenshot of the Printed events at OnOrderUpdate and OnBarUpdate. (Showing the complete filling of the TP-Orders; PartFilled and Filled are happening on the same second with total contracts value <Even while using Printing on each tick> )
private int [B]Quant [/B]= 10;
private Order [B]TP_Order [/B]= null;
private bool [B]TP_Check [/B]= false;
protected override void [B]OnStateChange[/B]()
{[INDENT]if (State == State.SetDefaults)
{[/INDENT][INDENT=2]...
Calculate = Calculate.[B]OnBarClose[/B];
...[/INDENT][INDENT]}
else if (State == State.Configure)
{[/INDENT][INDENT=2]AddDataSeries(i.FullName,BarsPeriodType.Minute, 15); //Trading Data Series
AddDataSeries(i.FullName,BarsPeriodType.Second, 30); //Additional Data Series for periodically 1 bar checks (Seconds)[/INDENT][INDENT]}[/INDENT]
}
protected override void [B]OnBarUpdate[/B]()
{[INDENT]if (CurrentBars[1] > 50 || CurrentBars[2] > 50) return;
if(BarsInProgress == 1){[/INDENT][INDENT=2]
if( [I]LONG Conditions[/I] ) [B]EnterLong([/B]1, Quant, @"[B]Buy[/B]"[B])[/B]
if( TP Conditions ) [B]ExitLong([/B]1, Quant, "[B]TP for Buy[/B]", "[B]Buy[/B]"[B])[/B][/INDENT][INDENT]}
[B]//Checking the TP order if it still in a Part-Filled after 30 Sec to Cancel it and submit Limit order instead.[/B]
if(BarsInProgress == 2){[/INDENT][INDENT=2]
if(TP_Order!=null && (TP_Order[B].[/B]Name == "[B]TP for Buy[/B]" || TP_Order[B].[/B]Name == "[B]New BUY TP[/B]") ){
[B]//Printing TP-Order Status/Quantity @ OnBarUpdate[/B]
Print([I]"InstName: " [/I]+ InstName
+[I]" | 30 Sec has passed | BuyTP Order Status: " [/I]+ TP_Order.OrderState
+[I]" | BuyTP Order Quantity: " [/I]+ TP_Order.Quantity
+[I]" | Time: " [/I]+ Time[0]);
[B]//Checking For Part-Filled Situation[/B][/INDENT][INDENT=3]if(TP_Check){[/INDENT][INDENT=4]if(Counter == 1){[/INDENT][INDENT=5]if(TP_Order[B].[/B]OrderState == OrderState[B].[/B]PartFilled){[/INDENT][INDENT=6][B]//Get Remaining Contracts[/B]
int RemainingQuant = Quant - TP_Order[B].[/B]Quantity;
[B]//Canceling the TP Order[/B]
CancelOrder(TP_Order);
[B]//Submitting EnterShortLimit[/B]
EnterShortLimit(1, false, RemainingQuant, GetCurrentBid(1), "[B]New BUY TP[/B]");
[B]//Reseting the Check & Counter[/B]
TP_Check = false;
Counter = 0;[/INDENT][INDENT=5]}[/INDENT][INDENT=4]
}else{[/INDENT][INDENT=5]Counter++;[/INDENT][INDENT=4]}[/INDENT][INDENT=3]}[/INDENT][INDENT=2]}[/INDENT][INDENT]}[/INDENT]
}
protected override void [B]OnOrderUpdate[/B](){[INDENT]
[B]//Detecting the TP order.[/B][/INDENT][INDENT]if(order.OrderAction == OrderAction.Sell && (order.Name == "[B]TP for Buy[/B]" || order.Name == "[B]New BUY TP[/B]")){[/INDENT][INDENT=2]
TP_Order = order;
TP_Check = true;
[B]//Printing TP-Order Status/Quantity @ OnOrderUpdate[/B]
Print([I]"InstName: " [/I]+ InstName
+[I]" | @OnOrderUpdate | BuyTP Order Status: " [/I]+ TP_Order.OrderState
+[I]" | BuyTP Order Quantity: " [/I]+ TP_Order.Quantity
+[I]" | Time: " [/I]+ Time[0]);
[B]//Reset the TP Order object to null if order was cancelled without any fill[/B]
if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
{[/INDENT][INDENT=3]TP_Order = null;
TP_Check = false;[/INDENT][INDENT=2]}[/INDENT][INDENT]}[/INDENT]
}
Thank you.

Comment