I am enclosing some sample code to show my problem.
if(targetLong!=null)
{
CancelOrder(targetLong);
targetLong=null;
targetLong = SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, sellpoint, 0, "TgtLong", "profit target long");
}
else
targetLong = SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, sellpoint, 0, "TgtLong", "profit target long");
Within the context of my entire code snippet shown above, when I backtest using the code above, I get the results I am expecting but have problems in real time as it will cancel the order on one bar and submit the new order on the next bar so I have targetLong working on every other bar when it should be working on the current bar.
In backtesting, this is not the case, the targetLong order is changed on every bar while the position is long. So I changed to code above and used the ChangeOrder method but now my backtest results are different but it acts right in realtime. See below for changed code snippet:
if(targetLong!=null)
{
ChangeOrder(targetLong, 1, sellpoint, 0);
}
else
targetLong = SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, sellpoint, 0, "TgtLong", "profit target long");
Shouldn't both code snippets do the same thing in backtesting since they are doing the same thing? I can see there is an issue in real time as perhaps the program in the first code snippet is waiting for a cancel confirmation before it submits the order therefore it gets skipped for one bar whereas in the second code snippet it just changes the order to the new level rather than cancelling and resubmitting. If I am wrong, please correct me!
I understand if this is a work in progress and there might be some things to resolve in the backtesting as unmanaged orders are a newer feature. What I am most concerned is that my code works right in real time. What I want to know is if there is an issue with the backtesting engine handling the ChangeOrder method or am I just plain wrong in my thinking with respect to the ChangeOrder method?
Thanks,
Cowpux
Comment