In OnBarUpdate I have the following type of code:
if (long conditions are met)
{
MyEntryOrder = EnterLongLimit(0, true, 1, longprice, "long limit order");
}
Simple profit & stop orders are placed:
stopOrder = ExitLongStop(0, true, 1, execution.Price - (10 * TickSize), "stop order", "long limit order");
targetOrder = ExitLongLimit(0, true, 1, execution.Price + (5 * TickSize), "target order", "long limit order");
Then I check for the appropriate instrument in each subsequent onBarUpdate calls:
if (BarsInProgress != 0)
return;
If it is the bar of the appropriate instrument, and 10 minutes have passed since entry, I issue an exit order:
if (BarsSinceEntry(0,"long limit order",0) > 10)
{
exitOrder = ExitLongLimit(0, true, 1, GetCurrentBid(), "long limit order exit", "long limit order");
}
When I run the script, it places the long order at an appropriate time as well as a stop order (Control Panel shows it in an ACCEPTED state) and a limit target order (Control Panel shows it in a WORKING state). If it lasts more than 10 bars, it issues the following error when the exit line is called:
Object reference not set to an instance of an object.
The same thing happens if I replace "long limit order" with the signal name of the target order ("target order"). If I put a call to ExitLongStop with the signal "stop order" I get the same result as well.
Do you have any advice or links which say how to properly issue exit statements in an automated strategy?
Comment