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/

    Running multiple strategies individually

    General Discussion
    2
    8
    485
    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.
    • E
      eric2020 last edited by

      Re: Running Multiple Strategies & Combining the Output

      I found that if multiple strategies are added to cerebro, they will work on the total position instead of their own positions, which makes them interact with eachother.

      Is there a switch or something so that I am able to let multiple strategies just handle the order and positions from their own? I just would like to see the result of simple sum of multiple strategies.

      Thanks.

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

        Position is maintained by broker - so if you need multiple strategies each working with its own broker - the option I see is to use multiple cerebro engine instances.

        (I'm now aware of a switch or option supporting multiple brokers or assigning broker per strategy)

        1 Reply Last reply Reply Quote 0
        • E
          eric2020 last edited by

          After checking the implement in strategy.py, I am afraid it is not easy to identify specific broker when buy or sell, even if multiple brokers are added to cerebro.

          1 Reply Last reply Reply Quote 0
          • E
            eric2020 last edited by

            It seems that only one broker is active even if multiple brokers are added, is it true?

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

              AFAIK there is no way to add multiple brokers to cerebro engine. The only method of adding a broker is setbroker, which just sets the _broker instance var in cerebro ( there is no even a space to store multiple brokers there )

                  def setbroker(self, broker):
                      '''
                      Sets a specific ``broker`` instance for this strategy, replacing the
                      one inherited from cerebro.
                      '''
                      self._broker = broker
                      broker.cerebro = self
                      return broker
              
              E 1 Reply Last reply Reply Quote 0
              • vladisld
                vladisld last edited by

                Alternatively you may try to cheat and add multiple data feeds (with the same data but different names), such that each strategy will know which data it is supposed to work on.

                This way the cerebro's broker will maintain separate positions for each data feed.

                However you still need to manage a common cash - which could be a showstopper depending on your needs.

                1 Reply Last reply Reply Quote 0
                • E
                  eric2020 @vladisld last edited by

                  @vladisld

                  Got it. Thank you.

                  BTW, if cerebro separate position and orders for each data feed, does it mean if different timeframe data of same instrument are added, the strategy cannot manage the total position or orders, but these of a single data?

                  ( it is like the opposite problem of the original one)

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

                    We are talking only about built-in broker class used for backtracking. Real-live broker classes (Oanda, IB, ...) get the position information directly from the real broker , so it doesn't matter if there will be multiple data feeds of the same instrument with different time-frames - the orders will be processed for a specific instrument and the position will be managed appropriately.

                    As for the BackBroker class (built-in broker used for backtracking) - although I never tried to trade on multiple time-frames simultaneously myself - AFAIU the position is maintained per data feed. I'm not sure there is a code in Backtrader that could identify that different data feeds actually belong to the same instrument.

                    Probably more experienced members on this forum could prove otherwise and point us to the corresponding source code.

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
                    $(document).ready(function () { app.coldLoad(); }); }