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/

    Optstrategy and PivotPoint indicator pickle error

    Indicators/Strategies/Analyzers
    3
    4
    440
    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.
    • Benjamin Kesby
      Benjamin Kesby last edited by

      Adding the pivot point indicator to a strategy results in a pickle error:

      File "/opt/emeraldmine/backtest.py", line 61, in run
          runs = self.cerebro.run(stdstats=stdstats)
        File "/usr/local/lib/python3.7/dist-packages/backtrader/cerebro.py", line 1143, in run
          for r in pool.imap(self, iterstrats):
        File "/usr/lib/python3.7/multiprocessing/pool.py", line 748, in next
          raise value
      multiprocessing.pool.MaybeEncodingError: Error sending result: '[<emeraldmine.strategies.pivot.PivotBase object at 0x7f9e3bea7710>]'. Reason: 'PicklingError("Can't pickle <class 'backtrader.metabase.LinesCoupler_0'>: attribute lookup LinesCoupler_0 on backtrader.metabase failed")'
      

      The strategy contains nothing but the initialising of the pivot point indicator with in init():

      class PivotBase(BaseStrategy):
          """Base strategy using built in PivotPoint indicator that uses 2 timeframes."""
          params = dict(
              open=False,
              close=False
          )
      
          def __init__(self):
              self.pivot = btind.PivotPoint(self.data1)
              # # CrossOvers
      
          def next(self):
              pass
      
      if __name__ == "__main__":
          pass
      
      

      This only happens when running optstrategy, obviously because of the pickling, any directions on a fix?

      1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        Please take a look at the following post: https://community.backtrader.com/topic/1977/multiprocessing-pool-maybeencodingerror

        Could this be relevant?

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

          The sample code is incomplete but the presence of

          @Benjamin-Kesby said in Optstrategy and PivotPoint indicator pickle error:

          if __name__ == "__main__":
              pass
          

          does clearly point in the direction indicated by @vladisld and the scoping problems that pickle has. The solution would be the same as the one outlined in the referenced post.

          Benjamin Kesby 1 Reply Last reply Reply Quote 1
          • Benjamin Kesby
            Benjamin Kesby @backtrader last edited by

            OK thank you, does this mean I cant keep strategies in separate files and import them? I have also wrapped a backtrader script in a class to allow for some easier configuration/ automation but i guess thats not possible with optstrategy also? Finally why would this error only occur with pivot points. All other indicators i've used so far do not create such an error.

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