PDA

View Full Version : Advanced Order Handling BarsInProgress > 0


whitmark
11-09-2007, 09:30 AM
I am testing out the advanced order functionality that is similar to what is listed in the help facility for the OnOrderUpdate method as well as the related reference example Josh posted:

private IOrder entryOrder = null;

protected override void OnBarUpdate()
{
if (entryOrder == null && Close[0] > Open[0])
entryOrder = EnterLong();
}

protected override void OnOrderUpdate(IOrder order)
{
if (entryOrder != null && entryOrder.Token == order.Token)
{
Print(order.ToString());
if (order.OrderState == OrderState.Filled)
entryOrder = null;
}
}

except that I am looking to place orders in BarsInProgressIndex = 1 vs 0 by replacing the entry logic with:


if (BarsInProgress == 1)
{
if (entryOrder == null && Close[0] > Open[0])
entryOrder = EnterLong(1, true, myOrderQty, Close[0], "myEntry");
}


Are there any special considerations to handle BarsInProgress = 1 orders when using the OnOrderUpdate method? I have been getting "Object reference not set to an instance of an object" run-tim errors when I attempt to do this.

Thanks,

Whitmark

NinjaTrader_Ray
11-09-2007, 09:37 AM
No there are no special considerations.

The code you pasted above should not produce an object reference error and it should be fine.

I suspect the error is coming from elsewhere. What I suggest to confirm that the above code is not producing this error is to comment out all other user code in the strategy and just let it run so that it places the one order as per your code. Assuming this works, you can then start uncommenting out other code to see where the object reference error is.

All this error means is that you are acessing a variable that holds an object but an object is not assigned to this variable.

whitmark
11-09-2007, 10:17 AM
Thanks Ray, good to know this will work without modification and in fact, your recommended debugging technique is exactly what I used to get to this point of inquiry. I am actually testing two entry orders . . . entryLongOrder and entryShortOrder.

protected override void OnOrderUpdate(IOrder order)
{
if (entryLongOrder != null && entryLongOrder.Token == order.Token)
{
if (order.OrderState == OrderState.Filled)
entryLongOrder = null;
}
if (entryShortOrder != null && entryShortOrder.Token == order.Token)
{
if (order.OrderState == OrderState.Filled)
entryShortOrder = null;
}
}

As you can see, in the OnOrderEvent logic I am testing both for != null and == to the order.Token. It would appear that when the OnOrderEvent triggers for one entry order object the and the other entry order object has not yet been assigned to its variable so I get the error message I described. Is there a best practice for handling multiple entryorders in this method to avoid this error? Thanks.

Whitmark

NinjaTrader_Ray
11-09-2007, 10:33 AM
Not sure I follow.

I the OnOrderUpdate() code you pasted could not produce an object reference error since you are checkking for null references before accessing properties on the object.

whitmark
11-09-2007, 03:03 PM
I started over with a simplified example and found that I could manage two separate orders and place the trades on the secondary series, no problem. Thanks for developing this functionality in the latest release.

Whitmark