Thanks. Forgot to mention - I'm using PyCharm.
The funny thing it that the code breaks only when there is no single completed transaction (i.e. no self.buy() and self.sell() in the strategy). Adding even a single transaction that is getting executed 'cures' the problem. This is a 'poor man's workaround' I'm now using....
afaik this is coming from IB, because of the nature of stoptraillimit orders. to place a valid stop-trail-limit order you will need the "limit price" at which you want to trail to start or an offset which is then used to calculate the "limit price". without either of these its not a valid stl order.
but the error could also mean you are specifying both limit price and limit price offset value, based on the above code you are only specifying plimit and not offset, so its coming from somewhere else. I saw one thread on ib_insync where this happened because TWS has a default offset is set in Order Presets configured. maybe you can check and confirm.
Could be the same behavior as the one reported in the following post:
It seems the IB store was designed with live trading in mind. The capability of loading the historical data was added as a mean for backfilling the historical data during live trading . So in this regard it less suitable for pure backtesting scenario.
Am I wrong ? Anyone having a different experience ?
@MislavSag said in Interactive brokers hang and plot:
When backtest finishes it doesn't show the graph and it doesn't stop. Even if I click ctrl + C, it just 'hangs'
The same behavior was also observed and discussed in the following post:
Unfortunately the fix wasn't as trivial - since the error codes 2105/2016 were sent in other scenarios as well - so since nobody was interested I've just abandoned the fix. Currently I'm just making my best to avoid such double connections :-(
try to initialize the Cerebro engine with preload=False:
cerebro = bt.Cerebro(stdstats=False, live=False, preload=False)
please report if it solved the problem. It seems that IBData will not report the end of historical data load ending properly in case the preload was requested - need to investigate further.
@chewbacca said in IB feeds question:
Does BT have to be restarted before each market open, or are there other options (i.e. running BT continuously) ?
Also BT could be run continuously, both TWS and TWS Gateway need to be restarted daily (https://financefeeds.com/interactive-brokers-adds-auto-restart-feature-tws-platform/) even with auto-restart feature enabled. It means all the data subscriptions need to be renewed anyway.
IMHO it is easier ( and cheaper if you run in cloud) to start/shutdown the system on (extended) trading session start/end every day. If in cloud - it even could be easily done using scheduling APIs.
Nevermind I figured it out. I wanted to do line[-5] as the value because this would fit the offsetting problem but it always gives errors, but I just had to basically skip the beginning of the line (where line[-5] didn't exist yet) and that fixed it. Sorry idk how I didn't figure this out last night guess I was just burned out. So yeah if anyone comes across this problem just basically do:
line[-5] = value you normally would put at line
and if you have a situation like mine, I had to use the pivot period so it was like above but had to convert the period to Int
@Atul-Patel were you able to get this done for IEX data? How did it compare to IB data feed? Did you find any issues with BT resampling for indicators as values are off like mentioned in my others posts.
Any updates on alternate and reliable data feed for Backtrader would be very much appreciated
@Mango-Loco Hi, it seems that I am working on the same issue.
But the code snippets are not enough for me to can solve my problem.
Can you please sent to me the complete code (without trading strategy) only the part to get the own data fields in backtrader, that I can use it as indicators.
Many thanks in advance.