I'm assuming this is simulated and that you're using the PaperBroker. In that case, it should not. The FillOrder function in PaperBroker has this check.
if (buyingPower + total_dBuyingPower - commission < 0)
information = "Not enough cash to fill order.";
I did poke around the code to see if I could find any gotchas or timing issues where BP would not represent actual BP. Would you mind putting the following lines in your system (perhaps before calling OpenPosition and maybe in OrderFilled)
double bp = this.SystemData.Broker.GetBuyingPower();
OutputMessage("Buying Power: " + bp.ToString());
I’m getting filled orders in backtesting an long equity system (margin = 0 for all symbols) that should be impossible due to the limited capital at the time of the trade. The system uses BarOnClosing and sets both CreateTicksFromBars and EnableTradeOnClose to true. For example, on 8/23 the system entered positions that left the account balance with enough for some fills the following day and exited those positions using BarOnClosing on 8/24 (close time 11:59 PM). However, the system also filled positions equal to the account value on 8/24 (submitted as limit orders on open with an actual fill time open time of 4:00 PM).
My expectation would be that the positions would not be filled if the account value would be exceeded. Note, there is not a way to limit the opening of positions in the above example because there is a possibility that the positions that were open on 8/23 could be closed due to a profit target allowing other positions to be filled. Note also that I have attempted to cancel pending open orders in NewTick for each symbol when account value would be exceeded and the time of the tick was > 3 PM. The orders were still filled at 4 PM.
Using 2010 Build 16.
Am I missing a margin or other setting? Why is the system allowing fills that exceed the account value? Why would the orders not be cancelled in NewTick if the cancellation occurred before base.NewTick? Other ideas to resolve?