When I set color as green, but the line plotted did not seem like green. The red seemed normal.
Posts made by jialeen
-
Some color of plot seems abnormal
-
RE: Backtesting multiple symbols with different date ranges - backtest won't start until all data feeds have data
I do this as follows:
class MyStrategy(bt.Strategy):
params = (('short', 5), ('long', 10))
def init(self):
self.inds = dict()
for i, d in enumerate(self.datas):
self.inds[d] = dict()
self.inds[d]['sma_s'] = bt.indicators.MovingAverageSimple(d.close, period=self.params.short)
self.inds[d]['sma_l'] = bt.indicators.MovingAverageSimple(d.close, period=self.params.long)
self.inds[d]['start_time'] = d.datetime.date(self.params.long)
self.inds[d]['start_flag'] = 0def prenext(self):
for i in range(3):
if self.datas[i].datetime.date() == self.inds[self.datas[i]]['start_time']:
self.inds[self.datas[i]]['start_flag'] = 1
log_str = log_str + 'i={}, date={}, sma_s={}, sma_l={}\n'.format(i, self.datas[i].datetime.date(),
self.inds[self.datas[i]]['sma_s'][0],
self.inds[self.datas[i]]['sma_l'][0])
elif self.inds[self.datas[i]]['start_flag'] == 1:
log_str = log_str + 'i={}, date={}, sma_s={}, sma_l={}\n'.format(i, self.datas[i].datetime.date(),
self.inds[self.datas[i]]['sma_s'][0],
self.inds[self.datas[i]]['sma_l'][0])prenext() process data when time is not the same. If the time is the same, then go to next().
-
all-in for buy
I ran backtest, and wanted to all-in for one stock. But it needed to set price and size, so I wondered if it could offer all-in mode when I used buy().