Backtrader Community

    • 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/

    If I add two strategies, how to manage the positions of each strategy

    General Discussion
    3
    2
    981
    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.
    • the world
      the world last edited by

      two strategies have the same next() method

          def next(self):
              for i,d in enumerate(self.datas):
                  pos = self.getposition(d)
                  if pos.size:
                      if self.inds[d]['signal'] < 0:
                          self.close(data=d)
                          print(self.p.name)
      
                  elif self.inds[d]['signal'] > 0:
                      self.buy(data=d)
              pass
      

      when I use these codes, the strategy will do short selling making the cash higher than the total account value. But I don't want to short, so how to make each strategy have their own position

      vladisld 1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld @the world last edited by

        @the-world AFAIK position is maintained by a broker per data and there is just a single broker per Cerebro engine. So in order for multiple strategies to have an independent positions, either they need to work on different datas or they need to be run using different engine instances.

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