For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
The next() call isn't called.
-
Hi there.
Basically, I want to use 5 seconds dataframe, but I want to use 8 hours dataframe for only the indicator.
But the next() call isn't called when I run the following code.(But The prenext() call is called.)
Am i doing something wrong?Thank in advance!!
class St(bt.Strategy): def __init__(self): self.rsi =rsi= bt.indicators.RelativeStrengthIndex(self.datas[1], upperband=80, lowerband=20) rsi.plotinfo.plot = False # rsi1 = rsi() # self.rsi_val = self.data0.close < rsi1.rsi def prenext(self): print("PRE-NEXT", self.data.close[0], self.rsi+0, self.data.datetime.datetime().strftime('%m-%d %H:%M:%S'), self.data1.datetime.datetime().strftime('%m-%d %H:%M:%S') ) def next(self): print("NEXT", self.data.close[0], self.rsi+0, self.data.datetime.datetime().strftime('%m-%d %H:%M:%S'), self.data1.datetime.datetime().strftime('%m-%d %H:%M:%S') ) def runstrategy(): # Create a cerebro cerebro = bt.Cerebro() storekwargs = dict( token="xxx", account="xxx", practice=False ) store = StoreCls(**storekwargs) DataFactory = store.getdata datakwargs = dict( timeframe=3, compression=5, qcheck=0.5, historical=False, fromdate=datetime.datetime(2020, 5, 1, 0, 0), todate=datetime.datetime(2020, 5, 2, 0, 0), bidask=None, useask=None, backfill_start=True, backfill=True, tz='Asia/Tokyo' ) data0 = DataFactory(dataname="USD_JPY", **datakwargs) data1 = cerebro.resampledata(data0, timeframe=bt.TimeFrame.Seconds, compression=5) data2 = cerebro.replaydata(data1, timeframe=bt.TimeFrame.Minutes, compression=480) # Add the strategy cerebro.addstrategy(St) # cerebro.run(exactbars=args.exactbars, stdstats=False, runonce=False,quicknotify=True) cerebro.run(exactbars=args.exactbars) print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue()) plt.rcParams['axes.unicode_minus']=False plt.rcParams['figure.figsize']=[18, 16] plt.rcParams['figure.dpi']=200 plt.rcParams['figure.facecolor']='w' plt.rcParams['figure.edgecolor']='k' cerebro.plot(iplot=False, style="candle") runstrategy()
output
PRE-NEXT 106.92 nan 05-01 00:00:00 05-01 00:00:00 PRE-NEXT 106.927 nan 05-01 00:00:05 05-01 00:00:05 PRE-NEXT 106.946 nan 05-01 00:00:10 05-01 00:00:10 PRE-NEXT 106.956 nan 05-01 00:00:15 05-01 00:00:15 : : :