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/

    How to plot two indicators on the same subplot?

    General Code/Help
    2
    3
    1039
    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.
    • J
      jesseliu0 last edited by

      Hi,

      In backtrader indicators can be plot in separate subplots if set subplot=True like this:

      sma10 = bt.indicators.MovingAverageSimple(self.datas[0].close, period=10, subplot=True)
      sma20 = bt.indicators.MovingAverageSimple(self.datas[0].close, period=20, subplot=True)
      

      They are shown on two separated subplots. If I want to place both SMAs on the same sub-plot (not with the data), so that I can see sma10 cross sma20, how can I code it? I read through the manual but did not find a way to specify which subplot an indicator to go. Can you please help? Thank you!

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

        Docs - Plotting - Option: plotmaster

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

          @backtrader said in How to plot two indicators on the same subplot?:

          Docs - Plotting - Option: plotmaster

          Cool. This works!
          Just a suggestion. Backtrader plots are based on matplotlib, while it may be better to be interactive plots for analyzing, such as plot.ly or bokeh. There is a 3rd-party add-on based on bokeh https://github.com/verybadsoldier/backtrader_plotting , but it's kind of buggy (at least for plotmaster). In the long term, maybe backtrader can consider migrate to bokeh or other interactive plotting library?

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