I'm having trouble with a strategy I'm working on where it keeps getting stuck in an infinite loop. It works properly until it gets to that specific bar (11/8/2013 8:00:00 AM), then it blows up and overflows my log. I've included a snippet of the log and the relevant code.
Here is the log:
11/8/2013 8:00:00 AM Entered internal SubmitOrder() method at 11/8/2013 8:00:00 AM: Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3433 OcoId='' Name='MyShortOrderStop' 11/8/2013 8:00:00 AM Entered internal SubmitOrder() method at 11/8/2013 8:00:00 AM: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3433 OcoId='' Name='MyLongOrder' 11/8/2013 8:00:00 AM: ooh, an execution. It's name is: MyShortOrderStop 11/8/2013 8:00:00 AM: ooh, an execution. It's name is: MyLongOrder 11/8/2013 8:00:00 AM Entered internal SubmitOrder() method at 11/8/2013 8:00:00 AM: Action=Sell OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3390 OcoId='' Name='MyLongOrderStop' 11/8/2013 8:00:00 AM Entered internal SubmitOrder() method at 11/8/2013 8:00:00 AM: Action=SellShort OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3390 OcoId='' Name='MyShortOrder' 11/8/2013 8:00:00 AM: ooh, an execution. It's name is: MyLongOrderStop 11/8/2013 8:00:00 AM: ooh, an execution. It's name is: MyShortOrder 11/8/2013 8:00:00 AM: Creating stop on short order... 1.3433 11/8/2013 8:00:00 AM: Current price is: 1.3415 11/8/2013 8:00:00 AM Entered internal SubmitOrder() method at 11/8/2013 8:00:00 AM: Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3433 OcoId='' Name='MyShortOrderStop' 11/8/2013 8:00:00 AM Entered internal SubmitOrder() method at 11/8/2013 8:00:00 AM: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3433 OcoId='' Name='MyLongOrder' 11/8/2013 8:00:00 AM: ooh, an execution. It's name is: MyShortOrderStop 11/8/2013 8:00:00 AM: ooh, an execution. It's name is: MyLongOrder 11/8/2013 8:00:00 AM Entered internal SubmitOrder() method at 11/8/2013 8:00:00 AM: Action=Sell OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3390 OcoId='' Name='MyLongOrderStop' 11/8/2013 8:00:00 AM Entered internal SubmitOrder() method at 11/8/2013 8:00:00 AM: Action=SellShort OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3390 OcoId='' Name='MyShortOrder' 11/8/2013 8:00:00 AM: ooh, an execution. It's name is: MyLongOrderStop 11/8/2013 8:00:00 AM: ooh, an execution. It's name is: MyShortOrder 11/8/2013 8:00:00 AM: Creating stop on short order... 1.3433 11/8/2013 8:00:00 AM: Current price is: 1.3415 11/8/2013 8:00:00 AM Entered internal SubmitOrder() method at 11/8/2013 8:00:00 AM: Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3433 OcoId='' Name='MyShortOrderStop' 11/8/2013 8:00:00 AM Entered internal SubmitOrder() method at 11/8/2013 8:00:00 AM: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3433 OcoId='' Name='MyLongOrder' **NT** Error on calling 'OnExecution' method for strategy 'SwingDonchian/f37ea7df53534f26bfdd70f879e6aa0b': Object reference not set to an instance of an object.
protected override void OnExecution(IExecution execution)
{
DonchianChannel dc = DonchianChannel(period);
myPrint ("ooh, an execution. It's name is: "+execution.Name);
if (execution.Name == "MyLongOrder") {
//myPrint("Creating stop on long order...");
longOrderStop = SubmitOrder(0, OrderAction.Sell, OrderType.Stop, 1, 0, dc.Lower[0], "", "MyLongOrderStop");
//longOrder = null;
shortOrder = SubmitOrder(0, OrderAction.SellShort, OrderType.Stop, 1, 0, dc.Lower[0], "", "MyShortOrder");
}
else if (execution.Name == "MyShortOrder") {
myPrint("Creating stop on short order... "+dc.Upper[0]);
myPrint("Current price is: "+Close[0]);
shortOrderStop = SubmitOrder(0, OrderAction.BuyToCover, OrderType.Stop, 1, 0, dc.Upper[0], "", "MyShortOrderStop");
//shortOrder = null;
longOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Stop, 1, 0, dc.Upper[0], "", "MyLongOrder");
}
What is going on? I thought I was following the rules and doing what I am supposed to be doing. I must use the Unmanaged Approach because my initial entry is an OCO bracket.
Please help me solve this bug.
-Matt

Comment