Sell nextday openprice
-
hello, I am trying to make voltalitybreakout strategy. My strategy is like buy stocks when Target price( yesterday (highprice - lowprice) * 0.5 ) is lower than today's HIGH price, then sell next day on next_price. But I have problem with Next open price, and I also would like to know to figure out the custom size. I mean this is multi-data on single strategy. If I want to trade maximum 10% of my total budget on each stock, How can I figure it out?
def __init__(self): self.inds = dict() for i, d in enumerate(self.datas): self.inds[d] = dict() self.inds[d]['OPEN'] = self.datas[0].open self.inds[d]['HIGH'] = self.datas[0].high self.inds[d]['LOW'] = self.datas[0].low self.inds[d]['CLOSE'] = self.datas[0].close self.inds[d]['PAYMENT_VOLUME'] = self.datas[0].PAYMENT_VOLUME self.inds[d]['RANGE'] = self.datas[0].high - self.datas[0].low self.inds[d]['TARGET'] = self.datas[0].open + self.inds[d]['RANGE'](-1)*0.5 self.inds[d]['NextOpen'] = self.datas[0].open(1) def next(self): for i, d in enumerate(self.datas): # dt, dn = self.datetime.date(d), d._name pos = self.getposition(d).size if not pos: if self.inds[d]['TARGET'][0] < self.inds[d]['HIGH']: #Calculate the max number of shares ('all in') # size = int(self.broker.getcash() / self.datas[0].open) - 1 ## self.buy(data=d, size=100000) elif self.inds[d]['NextOpen']: self.sell(data=d, size=100000) else: if self.inds[d]['TARGET'][0] < self.inds[d]['HIGH']: self.close(data=d) # Calculate the max number of shares ('all in') # size = int(self.broker.getcash() / self.datas[0].open) - 1 ## self.buy(data=d, size=100000) elif self.inds[d]['NextOpen']: self.close(data=d) self.sell(data=d, size=100000) # self.sell(data=d, size=self.position.size)
-
@wnwkr13 Yes you have a few issues going on.
@wnwkr13 said in Sell nextday openprice:
self.inds[d]['HIGH']
This is not a valid line in
next
. This is a full line and in next you need to grab usually the current bar. So would be:self.inds[d]['HIGH'][0]
@wnwkr13 said in Sell nextday openprice:
self.inds[d]['NextOpen'] = self.datas[0].open(1)
This is not a viable line eit5her. You can never look forward into next except on specific methods. Follow cheat-on-open as a guide.