PDA

View Full Version : Live until cancelled order without BarsInProgress index


bani789
09-02-2008, 01:06 PM
I'll try to explain what I'm intending to create and whether it's possible the best I can.

I'm trying to make a Multi-Instrument strategy, that loads say 30+ symbols. Criteria for entries are just copied and pasted under 30+ BarsInProgress == 0 till BarsInProgress == 30 if statements.

Entries are all taken fine but the stops is where I'm hitting some issues. The way I'm trying to place stops is using the OnPositionUpdate() method.

The problem is this: How would the stop differentiate on which symbol to place the stop on. The way I would do it for a single symbol is something like this, where different initial stop is used based on the entry taken: entryOrder1 would be one entry criteria while entryOrder2 would be a different entry criteria.


protectedoverridevoid OnPositionUpdate(IPosition position)
{
if (entryOrder1 != null && position.MarketPosition == MarketPosition.Long)
{
stopOrder1 = ExitLongStop (0, true, Position.Quantity, Low[0] - StopIncrement, "Trail Stop", "Entry");
}

if (entryOrder1 != null && position.MarketPosition == MarketPosition.Short)
{
stopOrder1 = ExitShortStop (0, true, Position.Quantity, High[0] + StopIncrement, "Trail Stop", "Entry");
}

if (entryOrder2 != null && position.MarketPosition == MarketPosition.Long)
{
stopOrder2 = ExitLongStop (0, true, Position.Quantity, MIN(Low, 3)[0] - StopIncrement, "Trail Stop", "Entry");
}

if (entryOrder2 != null && position.MarketPosition == MarketPosition.Short)
{
stopOrder2 = ExitShortStop (0, true, Position.Quantity, MAX(High, 3)[0] + StopIncrement, "Trail Stop", "Entry");
}
}


I supose my dillema is, how would I generalize this so it automatically places these stop orders for the correct instrument and not the one whose BarsInProgress index is 0, while still retaining the LiveUntilCancelled status.

Let me know if further clarification is needed.

EDIT: For example, entryOrder1 may come from BarsInProgress == 14, or it may come from BarsInProgress == 20, is there a way to "detect" which BarsInProgress index it came from so that the stop can be placed for the correct index?

NinjaTrader_Josh
09-02-2008, 01:12 PM
Aren't you using individual IOrder objects for each of your instruments? If the order comes from the IOrder that stemmed from instrument 1 you will know which barsInProgress to submit to. Just change the 0 to 1 for the barsInProgressIndex parameter.