Lean icon indicating copy to clipboard operation
Lean copied to clipboard

Futures Orders Fill On Extended Market Hours

Open AlexCatarino opened this issue 1 year ago • 2 comments

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))

Captura de ecrã 2024-06-13 231653

Checklist

  • [x] I have completely filled out this template
  • [x] I have confirmed that this issue exists on the current master branch
  • [x] I have confirmed that this is not a duplicate issue by searching issues
  • [x] I have provided detailed steps to reproduce the issue

AlexCatarino avatar Jun 13 '24 22:06 AlexCatarino

Proposed fix: https://github.com/AlexCatarino/Lean/tree/bug-8090-trailing-stop-futures

AlexCatarino avatar Jul 18 '24 19:07 AlexCatarino

Searching in the IB docs, I found that apparently, before it was allowed to make that kind of orders: image image

But now, it depends on the security and order type: image image

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: orth-rth-tws-order

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: image

Therefore, this change would also involve changes in the brokerage side.

Marinovsky avatar Aug 13 '24 18:08 Marinovsky