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/

    preventing labels for all data feeds showing when plotting

    General Code/Help
    2
    2
    647
    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
      sfkiwi last edited by

      I have a few hundred data feeds that Im running a portfolio strategy over. I would like to plot just the observer results and perhaps one of the data feeds as a reference but I haven't figured out how to turn off the data labels showing for the trades observer.

      I am setting plotinfo.plot = False for all the data feeds except the first one which seems to work when I use just 6 of the data feeds but when I add all the data feeds I get the plot show below.

      With all feeds
      0_1532551515241_Screen Shot 2018-07-25 at 10.41.48 PM.png

      With just 6 feeds
      0_1532552121784_Screen Shot 2018-07-25 at 10.54.32 PM.png

      #run
      cerebro = bt.Cerebro()
      cerebro.addstrategy(St)
      cerebro.broker.setcash(20000.0)
      cerebro.addobserver(bt.observers.TimeReturn, timeframe=bt.TimeFrame.NoTimeFrame)
      cerebro.addobserver(bt.observers.Benchmark, data=benchmark, timeframe=bt.TimeFrame.NoTimeFrame)
      cerebro.adddata(benchmark, name='SPY')
      for feed in feeds:
          cerebro.adddata(feed[1], name=feed[0])
      results = cerebro.run()
      cerebro.plot(iplot=False, style='candle')
      
      #strategy
      for d in self.datas:
          d.plotinfo.plot = False
      self.data1.plotinfo.plot = True
      
      B 1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators @sfkiwi last edited by

        @sfkiwi said in preventing labels for all data feeds showing when plotting:

        or all the data feeds except the first one

        @sfkiwi said in preventing labels for all data feeds showing when plotting:

        self.data1.plotinfo.plot = True
        

        That's not the first one, it is the second (arrays are 0 based)

        In any case, if it works for 6 data feeds it shall work for the rest. If a data feed has plotinfo.plot set to False, its name will not get added to the list of labels to be displayed. The code doesn't know if you added 6 or 1006 data feeds. The label will simply not be added (because the entire code that plots a data feed and its indicators will be skipped)

        In the plot above there are many labels for data feeds, which is an indication that the code was executed.

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors