I want to be able to ensure that the proper quantity of my stop orders is matched with the entries that were filled at all times. For example, if I submit a 10 lot and it gets filled, I immediately place a 10 lot stop order. However if the entry order is partially filled, I then place the stop order with the partially filled quantity and amend it with every fill coming in in the OnExecution method. That seems to work just fine.
What I want to do is write a method (lets call it CheckStops) that essentially goes through and 'matches' my entries with my placed stops - for quantity and to ensure that the stops are in fact placed (working or accepted). I call this method within OnBarUpdate with COBC=false. This is because my strategy is tick based and I want to ensure at all times that my entries have the properly placed stops for the entries. Under normal circumstances this is no problem. However once the stop gets partially filled, my STOP's quantity will be not equal to the entry's quantity (I guess I can check if the STOP is partially filled and then check the filled+quantity maybe) to determine if it adds up to it's entry.
However the trickier portion of this is to check the OrderState of the STOP orders. Essentially I'll be checking for whether the STOP is working, accepted, partially filled or filled. The problem is that because of the asynchronous nature of getting fills (of the STOPs) and checking quantities, my per-tick check seems to be insufficient.
In psuedocode this is what I'm doing in CheckStops():
//assume entryOrder and stopOrder are my C# Dictionaries
//assume my entry orders are named entry1, entry2, etc
//assume my stop orders are named entry1Stop, entry2Stop, etc
foreach entryKey in entryOrder
{
foreach stopKey in stopOrder
{
if stopKey.startsWith(entryKey)
{
// stop Order has been found for the entry order
// i want to make sure the quantity matches and the STOP is existent
// UNDER ALL CIRCUMSTANCES
}
}
}
Does anyone have a "trick" or some code I can look at that does this?
I'm using Unmanaged = true.
thanks!

Comment