Futures Orders Fill On Extended Market Hours
Expected Behavior
Trailing stop orders for futures fill outside market hours.
Actual Behavior
Trailing stop orders do not fill outside market hours.
Potential Solution
Overwrite TrailingStopFill method in FutureFillModel as we did for StopMarketFill.
Reproducing the Problem
from AlgorithmImports import *
class MyAlgorithm(QCAlgorithm):
def Initialize(self):
self.set_start_date(2024, 6, 3)
self.set_end_date(2024, 6, 4)
self.es = self.add_future("ES", extended_market_hours=True)
self.ticket = None
def on_data(self, slice):
if not self.ticket:
self.market_order(self.es.mapped, 1)
self.ticket = self.trailing_stop_order(self.es.mapped, -1, 5, False)
if self.ticket and self.ticket.status != OrderStatus.FILLED:
self.plot(self.es.mapped.value, 'Price', self.es.price)
self.plot(self.es.mapped.value, 'Stop', self.ticket.get(OrderField.STOP_PRICE))
Checklist
- [x] I have completely filled out this template
- [x] I have confirmed that this issue exists on the current
masterbranch - [x] I have confirmed that this is not a duplicate issue by searching issues
- [x] I have provided detailed steps to reproduce the issue
Proposed fix: https://github.com/AlexCatarino/Lean/tree/bug-8090-trailing-stop-futures
Searching in the IB docs, I found that apparently, before it was allowed to make that kind of orders:
But now, it depends on the security and order type:
Furthermore, in TWS one can test that a box need to be manually checked in order to allow the order to be filled outside RTH:
I tested this manually, trying to submit a trailing stop order for ES future but the option to fill the order outside RTH didn't appear.
Instead I found an option to trigger the order outside RTH:
Therefore, this change would also involve changes in the brokerage side.