All strategy methods onTick onBar onMessage etc are called in one strategy thread.
waitForUpdate() is working in tester pretty much like in real time environment, it's not waiting real 10 seconds of course, but it skips ticks for that time like real engine would do. In your case order executed by market price, so it should return immideatly
problem with your code is that order goes through two states when you submit it. First it changes it's state to OPENED which means server accepted it, and then to FILLED when server fills it. In real time environment server usually sends only FILLED status for market orders or rejects them that's why it works, but in theory it could happen that it first sends OPENED and then strategy will fail like in tester.
You could change your code like that:
pBuyOrder = engine.submitOrder(getLabel(instrument), instrument, IEngine.OrderCommand.BUY, iLots);
while (pBuyOrder.getState() == IOrder.State.CREATED || pBuyOrder.getState() == IOrder.State.OPENED) {
pBuyOrder.waitForUpdate(10000);
}
if (pBuyOrder.getState() == IOrder.State.FILLED)
{
do some stuff...
}
else
{
we have a problem...
}
You can add some check also if you want to be sure it will not turn to infinite cycle
int i = 3; //no more than three times
while ((pBuyOrder.getState() == IOrder.State.CREATED || pBuyOrder.getState() == IOrder.State.OPENED) && i > 0) {
pBuyOrder.waitForUpdate(10000);
--i;
}
Quote:
Will the backtester engine call my onBar() before it has exited?
Do you mean onStop()? If so, then yes, onStop will be called