I came across some behavior which at first glance was peculiar, but upon inspection might not be.
In this case, my strategy was in OnBarUpdate(). Within this the code to update stops (UpdateExits())comes before the code that initializes new positions or increases existing positions.
In LIVE TESTING (that is, live data with an IB paper account), the following happened which I can't re-create in BACKTESTING:
1.)OnBarUpdate() is called.
2.)Call to UpdateExit() within OnBarUpdate().
3.)Stop updated and triggered within UpdateExit().
4.)Position flattened by UpdateExit();
now here's the tricky part.
5.)OnBarUpdate() resumes on the same bar that UpdateExits() was called on above.
6.)Because position is now flat, it was possible to initialize a new position.
7.)New position initialized.
Now, this wasn't actually a huge problem - technically, I did want to get stopped out and, technically, the conditions were correct to initiate a new position. That wasn't the problem.
The problem is that I can't seem to replicate this behavior in backtesting.
While I suspect it might have to do something with Sim 101 account settings (specifically, the communications and exchange delay settings), I want to make sure that it isn't something else.
So to sum this, here's my question: Can OnPositionUpdate() interrupt OnBarUpdate()?
Comment