Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    how to disable plotting resample data

    General Discussion
    4
    10
    1622
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      stentor last edited by

      Is there any way to disable plotting resample data? I tried and failed to figure it out.
      thanks a lot!

      1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by ab_trader

        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
        
        • If my answer helped, hit reputation up arrow at lower right corner of the post.
        • Python Debugging With Pdb
        • New to python and bt - check this out
        S B 2 Replies Last reply Reply Quote 0
        • S
          stentor @ab_trader last edited by

          @ab_trader I tried, but it only disable plotting the original data, not the resampled data.

          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators last edited by

            @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?

            1 Reply Last reply Reply Quote 0
            • S
              stentor last edited by

              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

              1 Reply Last reply Reply Quote 0
              • B
                backtrader administrators @ab_trader last edited by

                @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 documentation

                • Docs - Cerebro

                Or receive the resampled data instance as the result of calling resampledata and do as told by @ab_trader

                1 Reply Last reply Reply Quote 0
                • S
                  sorosrex last edited by

                  backtrader v1.9.74.123
                  python v3.7.3

                  The above discussion still doesn't clear it for me.
                  Aim:

                  1. To NOT print any resampled data but use it in my strategies.
                  2. To print non-resampled data as well as use it in my strategies.

                  What I have already tried:
                  Strategy Code

                  class 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 function

                  cerebro = 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

                  S 2 Replies Last reply Reply Quote 0
                  • S
                    sorosrex @sorosrex last edited by

                    @ab_trader @backtrader

                    1 Reply Last reply Reply Quote 0
                    • S
                      sorosrex @sorosrex last edited by

                      Solved by using data.name.plotinfo.plot = False inside __init__ of strategy

                      self.dnames.minutely.plotinfo.plot = False
                      
                      1 Reply Last reply Reply Quote 0
                      • A
                        ab_trader last edited by

                        You can try the following:

                        rdata = cerebro.resampledata(...)
                        rdata.plotinfo.plot = False
                        
                        • If my answer helped, hit reputation up arrow at lower right corner of the post.
                        • Python Debugging With Pdb
                        • New to python and bt - check this out
                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post
                        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors