If I add two strategies, how to manage the positions of each strategy
the world last edited by
two strategies have the same next() method
def next(self): for i,d in enumerate(self.datas): pos = self.getposition(d) if pos.size: if self.inds[d]['signal'] < 0: self.close(data=d) print(self.p.name) elif self.inds[d]['signal'] > 0: self.buy(data=d) pass
when I use these codes, the strategy will do short selling making the cash higher than the total account value. But I don't want to short, so how to make each strategy have their own position
vladisld last edited by
@the-world AFAIK position is maintained by a broker per data and there is just a single broker per Cerebro engine. So in order for multiple strategies to have an independent positions, either they need to work on different datas or they need to be run using different engine instances.
same here. thanks for sharing!