PDA

View Full Version : Help with monitoring Stop orders


jonmoron
08-03-2010, 10:21 PM
Hi,

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!

NinjaTrader_Bertrand
08-04-2010, 08:48 AM
jonmoron, havw you considered checking the status in OnOrderUpdate()?

http://www.ninjatrader.com/support/helpGuides/nt7/onorderupdate.htm

jonmoron
08-04-2010, 12:08 PM
Bertrand,

Im not sure you understand the purpose behind this method. I want to check my stop order's presence at every tick and make sure the proper quantity is placed and working for my position.

This is why I call CheckStops() in OnBarUpdate. I was looking for a nice algo that would satify my needs.

thanks

NinjaTrader_Bertrand
08-04-2010, 12:35 PM
Perhaps not, but what I understood is you looked for a way to access the different orderstates (partials) your stops would go through, this can be done in the OnOrderUpdate() for your strategy, as it would be called for each orderstate change.