how to disable plotting resample data
-
Is there any way to disable plotting resample data? I tried and failed to figure it out.
thanks a lot! -
Plotting of any data can be turned off using the
plot
parameter when you define your data feed (data
is your resampled data feed):data = bt.feeds.GenericCSVData(dataname=datapath, fromdate=dt.datetime(1900, 1, 1), todate=dt.datetime(2018, 12, 31), plot=False)
or (didn;t use it but should work)
data = bt.feeds.GenericCSVData(dataname=datapath) data.plotinfo.plot = False
-
@ab_trader I tried, but it only disable plotting the original data, not the resampled data.
-
@ab_trader is telling you how to disable plotting for any data, because you are not showing any code and thus cannot tell where you are doing things wrong
Have you done that for the resampled data instance?
-
data = bt.feeds.PandasData(dataname=dt, plot=False)
cerebro.adddata(data=data, name='I000016Min5')
cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes, compression=1)I use the above code but I am not sure where to put 'plot=false' for resample data. Your advice is much appreciated! thanks
-
@ab_trader said in how to disable plotting resample data:
data.plotinfo.plot = False
As indicated by @ab_trader you don't have to put necessarily in the constructor, but if you wish pass it to
resampledata
as indicated by the documentationOr receive the resampled data instance as the result of calling
resampledata
and do as told by @ab_trader -
backtrader v1.9.74.123
python v3.7.3The above discussion still doesn't clear it for me.
Aim:- To NOT print any resampled data but use it in my strategies.
- To print non-resampled data as well as use it in my strategies.
What I have already tried:
Strategy Codeclass TestStrategy(Strategy): def __init__(self): self.close = self.datas[0].close self.sma_minutely = SMA(self.dnames.minutely, period=10) def next(self): pass
Scenario A: plot=False in
resampledata
functioncerebro = Cerebro(stdstats=False) data = btfeeds.GenericCSVData( timeframe=TimeFrame.Seconds, dataname=datapath, dtformat=('%Y-%m-%d %H:%M:%S'), volume=-1, openinterest=-1 ) cerebro.adddata(data) cerebro.resampledata(data, name='minutely', timeframe=TimeFrame.Minutes, compression=1, plot=False) cerebro.addstrategy(TestStrategy) cerebro.run() cerebro.plot(volume=False, openinterest=False, style='candle')
Result A:
Traceback (most recent call last): File "main.py", line 36, in <module> timeframe=TimeFrame.Minutes, compression=1, plot=False) File "<masked>/backtrader/cerebro.py", line 839, in resampledata dataname.resample(**kwargs) File "<masked>/backtrader/feed.py", line 592, in resample self.addfilter(Resampler, **kwargs) File "<masked>/backtrader/feed.py", line 332, in addfilter pobj = p(self, *args, **kwargs) File "<masked>/backtrader/metabase.py", line 88, in __call__ _obj, args, kwargs = cls.doinit(_obj, *args, **kwargs) File "<masked>/backtrader/metabase.py", line 78, in doinit _obj.__init__(*args, **kwargs) TypeError: __init__() got an unexpected keyword argument 'plot'
Scenario B: plot=False inside
GenericCSVData
data = btfeeds.GenericCSVData( timeframe=TimeFrame.Seconds, dataname=datapath, dtformat=('%Y-%m-%d %H:%M:%S'), volume=-1, openinterest=-1, plot=False )
Result B: Plots everything except original data (timeframe=seconds). Not desireable.
Scenario C: Using
data.plotinfo.plot=False
data = btfeeds.GenericCSVData( timeframe=TimeFrame.Seconds, dataname=datapath, dtformat=('%Y-%m-%d %H:%M:%S'), volume=-1, openinterest=-1 ) cerebro.adddata(data) cerebro.resampledata(data, name='minutely', timeframe=TimeFrame.Minutes, compression=1) data.minutely.plotinfo.plot = False cerebro.addstrategy(TestStrategy) cerebro.run() cerebro.plot(volume=False, openinterest=False, style='candle')
Result C:
Traceback (most recent call last): File "main.py", line 45, in <module> data.minutely.plotinfo.plot = False File "<masked>/backtrader/lineseries.py", line 461, in __getattr__ return getattr(self.lines, name) AttributeError: 'Lines_LineSeries_DataSeries_OHLC_OHLCDateTime_Abst' object has no attribute 'minutely'
Scenario D: Using data._name with everything else similar to Scenario C
data._minutely.plotinfo.plot = False
Result D:
Traceback (most recent call last): File "main.py", line 45, in <module> data._minutely.plotinfo.plot = False File "<masked>/backtrader/lineseries.py", line 461, in __getattr__ return getattr(self.lines, name) AttributeError: 'Lines_LineSeries_DataSeries_OHLC_OHLCDateTime_Abst' object has no attribute '_minutely'
Please guide me to hide plots of resampled data in light of new information above (while allowing me to use it in my strategies).
Cheers
-
-
Solved by using data.name.plotinfo.plot = False inside
__init__
of strategyself.dnames.minutely.plotinfo.plot = False
-
You can try the following:
rdata = cerebro.resampledata(...) rdata.plotinfo.plot = False