I need to write to a database when there is a stop loss order filled, I've attached the code below
My problem is, sometime, even though the strategy is using 3 set of param but all outstanding orders may hit stop loss at the same time, i can see from the execution tab that, all 3 stop orders are filled, but sometime, the database miss 1 or 2 orders data. Similarly, 3 long/short orders enter at the same time is possible, but so far i have not have any error on those orders
I have never had problem with Pentium + Windows 7 combo, but after I change the box to Xeon + Windows 7, I start to notice the error
I suspect it is only a problem for cut loss order is because the stop loss is filled very quickly (unlike the long/short orders, which require the onBarUpdate() to be called and each onBarUpdate() can take about 100-300 ms to run)
is there any insight from your side?? thanks
protected override void OnOrderUpdate(IOrder order)
{
// If OnOrderUpdate() is called from a stop loss or profit target order add it to the appropriate collection
if (order.OrderState == OrderState.PendingSubmit)
{
// Add the "Stop loss" orders to the Stop Loss collection
if (order.Name == "Stop loss")
stopLossOrders.Add(order);
// Add the "Profit target" orders to the Profit Target collection
else if (order.Name == "Profit target")
profitTargetOrders.Add(order);
}
// Process stop loss orders
if (stopLossOrders.Contains(order))
{
// Check order for terminal state
if(order.OrderState == OrderState.Filled)
{
//stop loss filled
Print("Stop Loss");
if(order.OrderAction==OrderAction.Buy || order.OrderAction==OrderAction.BuyToCover)
{
//log
}
else if(order.OrderAction==OrderAction.SellShort || order.OrderAction==OrderAction.Sell)
{
//log
}
}
if (order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Filled || order.OrderState == OrderState.Rejected)
{
// Print out information about the order
Print(order.ToString());
// Remove from collection
stopLossOrders.Remove(order);
}
}
// Process profit target orders
if (profitTargetOrders.Contains(order))
{
// Check order for terminal state
if(order.OrderState == OrderState.Filled)
{
//profit target filled
Print("Profit Target");
if(order.OrderAction==OrderAction.Buy || order.OrderAction==OrderAction.BuyToCover)
{
//log
}
else if(order.OrderAction==OrderAction.SellShort || order.OrderAction==OrderAction.Sell)
{
//log
}
}
if (order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Filled || order.OrderState == OrderState.Rejected)
{
// Print out information about the order
Print(order.ToString());
// Remove from collection
profitTargetOrders.Remove(order);
}
}
}
Comment