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/

    Disable plotting backtrader.indicator.PivotPoint

    Indicators/Strategies/Analyzers
    2
    2
    389
    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.
    • servantfox
      servantfox last edited by

      Hi,

      I'm having issue with disabling the plot for the PivotPoint. Despite parsing "plot=False", the end result still plotting.

      class MyStrat(bt.Strategy):
          params = dict(
              pivot_algo=bt.indicators.PivotPoint,
          )
      
          def __init__(self):
              self.pivot = collections.defaultdict(dict)
              self.inds = collections.defaultdict(dict)
              # Decouple datas
              # First half is the daily, second half is monthly
              total_data = len(self.datas)
              self.daily = self.datas[:total_data//2]
              self.monthly = self.datas[total_data//2:]
      
              for d in self.monthly:
                  self.pivot[d] = self.p.pivot_algo(d, plot=False, plotvaluetags=False, plotlinevalues=False)
      

      my main:

          cerebro = bt.Cerebro() # cerebro engine
          data = bt.feeds.GenericCSVData(
                  dataname="stk_database/AIRASIA_5099_historical.csv",
                  fromdate=begin_date,
                  openinterest=-1,
              )
          cerebro.adddata(data)
      
          cerebro.resampledata(data, timeframe=bt.TimeFrame.Months).plotinfo.plot = False
          #cerebro.broker.set_cash(1000)
          cerebro.addstrategy(MyStrat) # Add the trading strategy
          #cerebro.addsizer(TestStake)
          #cerebro.broker.addcommissioninfo(CommInfoStock())
      
          print(f"Starting value is {cerebro.broker.getvalue()} with cash of {cerebro.broker.getcash()}")
          results = cerebro.run()  # run it all
          print(f"Final value is {cerebro.broker.getvalue()} with cash of {cerebro.broker.getcash()}")
          cerebro.plot(style="candlestick")
      

      Result:
      7cecd053-5c36-4c0c-b1ae-e8b4e7831fdd-image.png

      I also tried with plotinfo.plot=False on the indicator, seems to give same result.

      Thank you in advance.

      1 Reply Last reply Reply Quote 0
      • run-out
        run-out last edited by

        Did you try this?

        The indicator will try to automatically plo to the non-resampled data. To disable this behavior use the following during construction:

        _autoplot=False

        RunBacktest.com

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