During algorithm testing I've noticed when using 'Schedule_Function' and 'order_target_percent' that if the orders aren't filled within the specified day, the open order carries over until the next 'Schedule_Function' call. For example, a monthly scheduled buy order 15 minutes before close, if not filled that day appears to stay open until the next month's 'Schedule_Function' call in which case it tries to fill the order out of sequence which really mucks up the strategy.
I could use a simple cancel all orders code block but then portfolio allocation is affected.
Within the community I've only seen this issue addressed using a 'cancel all orders' code block when integrated with a 'Schedule Function' or the orders are handled within the 'handle_data' call using some combination of 'get_datetime()' and datetime tracking without the use of 'Schedule Function', which goes against the recently published "Tips for Writing Robust Algorithms for the Hedge Fund"
Any help is appreciated.