I think you missed my point, James, so let me be clearer.
The code now reads
if (context.hour > 11) or (context.minute > 55):
order(sid(24), 50)
Before noon, this should trade only for the last few minutes of each hour. After noon, it should trade every minute.
On the second day of the back test (and all subsequent days), the Transaction Details for the backtest of this code records trades at:
9:31
9:57
9:58
9:59
10:00
10:57
10:58
10:59
11:00
11:57
11:58
11:59
12:00
... and then every minute for the rest of the day
The problem is the very first trade of the day. 9:31 AM is NEITHER hours > 11 NOR minutes > 55 and yet a trade is executed. You can't stop that first order of the day this way!
I figured out I could fudge my way around this with the code:
if context.hour == 16:
pass
elif (context.hour >= 12) or (context.minute > 55):
order(sid(24), 50)
Apparently there is some bug that orders from the previous day ARE carried over to the next day. That would explain why the very FIRST day never had the order at 9:31. So by forcing the code to "PASS" at 4:00 PM the previous day, that opening order is NOT carried over.