I am a bit of a noob here and really rusty with programming. I have explored backtrader during covid and hit the wall (obviously) since this field is really tough. But am looking to get back into this. Previously I have ever only used 1 data or symbol to back test. And I like to expand to multiple symbols or multiple stocks.
I am working on my old code that runs without errors but finding it really hard to get my head round to converting it to multiple symbols/multiple stocks, also have difficulty to find enough code examples to infer from. (I have like 3 sets - 1 from bt, 1 from backtest rookie and 1 from this forum. ) . I am working on a 1 stategy, multiple symbol code.
class BaseStrategy(bt.Strategy): # params apply to all symbols params = dict(data_id=None, atrperiod=14, emaperiod=200) def __init__(self): # this following 2 lines are not symbol specific so I declare as such. self.early_close_days = get_early_close_days() self.data_live = False for i, sym in enumerate(self.datas): self.datas[i].notoptimize = True # this is a variable that i use that might be different for different symbol. so if lets say i have twtr and tsla, twtr might be True, tsla might be False # below lines I control every order self.datas[i].long_parent_order, self.datas[i].long_stoploss, self.datas[i].long_partial, self.datas[i].long_trailstop = None, None, None, None self.datas[i].short_parent_order, self.datas[i].short_stoploss, self.datas[i].short_partial, self.datas[i].short_trailstop, self.datas[i].early_exit = None, None, None, None, None
My question is, is self.datas[i].notoptimize correct? or should it be sym.notoptimize or is this bad programming totally. Any suggestions welcome.