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/

    With a strategy with multiple instruments, anyway to make one plot per?

    General Discussion
    3
    7
    1358
    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.
    • C
      CptanPanic last edited by

      I have multiple instruments with corresponding data feeds. The resultant plot() is way too busy, and would like to have a plot() for each instrument, even if that meant that the top portfolio section is the same between plots. Can this be done?

      Thanks.

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

        No and yes. Plots are strategy-based and not data-based.

        But you could selectively disable which data feeds have to be shown and then replot. This is completely untested, but it should be something like this:

        st = cerebro.run(....)[0]  # assume only interest in 1st strategy (probably the only one)
        
        for i in range(len(st.datas)):
            for j, d in enumerate(st.datas):
                d.plotinfo.plot = i == j
                
            cerebro.plot()
        
        vhphan 1 Reply Last reply Reply Quote 0
        • C
          CptanPanic last edited by

          Thanks,
          That does work. Alternatively is there a way to get access to this raw data so I can plot myself?

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

            Each line in a data feed has:

            • An attribute array which holds the data
            • Method getzero(idx, size) to return the data from the beginning
            • Method plot(idx=0, size=None) which if called as plot() will simply give you the entire array
            1 Reply Last reply Reply Quote 0
            • vhphan
              vhphan @backtrader last edited by

              @backtrader
              This works for me but all the buy/sell signal is on the first plot.
              How do I plot the buy/sell signal for each datafeed on its own separate plot?
              Thanks in advance.

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

                @vhphan said in With a strategy with multiple instruments, anyway to make one plot per?:

                but all the buy/sell signal is on the first plot.

                You probably bought and sold only what's on the first plot.

                @vhphan said in With a strategy with multiple instruments, anyway to make one plot per?:

                How do I plot the buy/sell signal for each datafeed on its own separate plot?

                That happens automatically. But we don't know what you have done and how, so there is no way to tell what, why, how ...

                vhphan 1 Reply Last reply Reply Quote 0
                • vhphan
                  vhphan @backtrader last edited by

                  @backtrader
                  Thanks.
                  You are right. I did bought and sold on the first plot.
                  I managed to fix the code.

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