For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Resample data and indicator
-
I am currently resampling data, and then using that in a simple moving average indicato. The output then is a second chart with the resampled data and moving average, however I would like to have the moving average (based on weekly data) to be plotted on the main layout, is this possible?
Code:
"""
class MovingAverage(bt.Strategy):params = ( ('ema5', 5), ('ema20', 8), ('ema50', 50), ('ema_200', 200), ('printlog', True), ('atr_mult', 2.0), ('rsi_period', 30), ('atr_period', 14), ) def log(self, txt, dt=None, doprint=False): if self.p.printlog or doprint: dt = dt or self.datas[0].datetime.date(0) print('%s, %s' % (dt.isoformat(), txt)) def __init__(self): self.dataclose = self.data.close self.ema5 = bt.ind.EMA(self.data1, period=self.p.ema5) self.ema20 = bt.ind.EMA(self.data2, period=self.p.ema20) self.rsi = bt.ind.RSI_SMA(period=self.p.rsi_period, plot=True) self.atr = bt.ind.ATR(period=self.p.atr_period, plot=False) self.crossup = bt.ind.CrossUp(self.data0, self.ema5, plot=False) self.addminperiod(45) self.order = None
if name=='main':
cash = 10000
position = cash
cerebro = bt.Cerebro(optreturn=True, stdstats=True)data = bt.feeds.GenericCSVData( dataname="litecoin_unix_daily.csv", fromdate=datetime.datetime(2017, 1, 1), # todate=datetime.datetime(2022, 3, 30), timeframe=bt.TimeFrame.Minutes, compression=1, nullvalue=0.0, dtformat=2, datetime=0, open=1, high=2, low=3, close=4 ) cerebro.adddata(data, name='data') cerebro.resampledata(data, timeframe=bt.TimeFrame.Weeks, compression=1) cerebro.resampledata(data, timeframe=bt.TimeFrame.Months, compression=1)
"""