@vuduclong0309, I rebuilt the part of the algo that calls to backfill the data into a separate module that runs on its own, it wasnt the ideal solution but has worked so my algo now only calls live data.

Latest posts made by sickboy_76au
-
RE: IB market data subscriptions & End Date/Time: The date, time, or time-zone entered is invalid.
-
RE: IB market data subscriptions & End Date/Time: The date, time, or time-zone entered is invalid.
Hi everyone, I am experiencing the same issue. was moving house and hadnt run my algo for a month or so just got setup and it stopped working. Traced it to IB requiring date data in YYYYMMDD format. My code checks the last date for data and begins pulling from that date, that format is used throughout the program so changing it is problematic as it is different to format backtrader uses, any other ideas would be really appreciated.
-
RE: Cancel Individual Order in IB
Thanks for your reply Vladsisld, yes recreating the old order to cancel it sounds like a bit of a step too far for me.
Yes I have had to build out the position and order management completely separately. I am fortunate that the strategy is fairly simple and runs once a day, this may not be possible for more active traders, so I place orders in to enter positions good for the day that way if they are filled it is in my position and if not filled the strategy won't double up the entry order the following day. I therefore am able to utilise a separate script outside of backtrader to check my positions and orders and update them as needed. I have that script on a schedule running every few hours during trading days.
There are other changes to the orders I make, backtrader allows me to place only certain types of orders, so my order management script checks all my working orders each time it runs and updates the bracket orders to allow trailing stops and eventually to utilise the IB algos etc, it also checks the positions and makes sure I have the right amount of orders for each position. its not ideal to run that order management separately but it seems to be working for me for now.
I do like using backtrader, it has been an excellent tool and a great way to learn python over the last year or so, I am sure my code is terrible but the simplicity of the platform has allowed me to build a working Algo so thank you to everyone who contributed to it.
-
Cancel Individual Order in IB
Hi everyone,
I have a strategy up and running well on IB paper trader.
In the strategy I have many orders working across a number of FX currency pairs. During the strategy there are times I need to cancels orders on one currency pair with out affecting the others. I have the live orders stored and managed in a CSV file locally that updates regularly to stay updated with fills etc.
So when I need to cancel a particular order I can call it from my CSV and obtain the OrderId or any other information required. I tried the below line but got the attribution error can anyone please help me troubleshoot this?
myOrder.OrderId.values returns the OrderId in this case 6281 as an integer
self.cancel(myOrder.OrderId.values)
Traceback (most recent call last):
File "/Users/~~~~~~~/opt/anaconda3/lib/python3.7/site-packages/backtrader/brokers/ibbroker.py", line 310, in cancel
o = self.orderbyid[order.m_orderId]
AttributeError: 'numpy.int64' object has no attribute 'm_orderId'Thanks
-
RE: Indicator - High since most recent Low
Thanks that worked .... I had an issue with kicking off the calc at the right time as this was an indicator on another indicator which is an average of another average, so had to find a way to delay the start. but the below is not very pretty but it worked. I think it might be better in a new indicator class but I kept getting a variety of errors with that and my python isn't good enough. Thanks for the help.
def __init__(self): #keep a reference to the close self.dataclose = self.datas[0].close self.dataopen = self.datas[0].open self.datahi = self.datas[0].high self.datalo = self.datas[0].low self.datadate = self.datas[0].datetime self.dmi = btind.DirectionalMovement(period = self.params.fastdays) self.dyn_adx_hi = [0,] self.dyn_adx_lo = [0,] def next(self): if len(self.dmi.adx) > (self.params.fastdays)*3+1 and len(self.dmi.adx) <=(self.params.fastdays)*3+2: self.dyn_adx_hi[0] = self.dmi.adx[-1] self.dyn_adx_lo[0] = self.dmi.adx[-1] if len(self.dmi.adx) > (self.params.fastdays)*3+2: if self.dmi.adx[0] > self.dyn_adx_hi[-1] or self.dmi.adx[0] >= self.dmi.adx[-1]: self.dyn_adx_hi[0] = self.dmi.adx[0] self.dyn_adx_lo[0] = self.dyn_adx_lo[-1] elif self.dmi.adx[0] < self.dyn_adx_lo[-1] or self.dmi.adx[0] < self.dmi.adx[-1]: self.dyn_adx_lo[0] = self.dmi.adx[0] self.dyn_adx_hi[0] = self.dyn_adx_hi[-1]
-
Indicator - High since most recent Low
Hi,
I am relatively new to python and backtrader, and am struggling to create an addition to the DMI indicator where I track the recent High or Low ADX, and reset the Low after a new high is established and then reset the high once a new low is in place rather than take the high and low for a particular period.I can find the low or high for a period as below
self.dmi = btind.DirectionalMovement(period = self.params.fastdays)
self.ADXhi = bt.indicators.Highest(self.dmi.adx, period = self.params.fastdays)
self.ADXlo = bt.indicators.Lowest(self.dmi.adx, period = self.params.fastdays)but how can I make it more dynamic so that if for example the ADX continues to set new highs the ADX low does not change till the high is in place?