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/

    Indicators - different subplot values for different lines

    Indicators/Strategies/Analyzers
    3
    7
    2715
    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.
    • T
      ThatBlokeDave last edited by ThatBlokeDave

      Hello

      I have developed an indicator that can provide signals when a price hits a simple trend line.

      My signal line is currently on a subplot . However I would also like to plot my trend line on the main plot so I can easily see afterwards what is going on.

      In other words:

      Signal Line: subplot = True
      Trend Line: subplot = False

      I didn't spot anything in the line specific plotting options in the docs (https://www.backtrader.com/docu/plotting/plotting.html)

      Thanks!

      A 1 Reply Last reply Reply Quote 0
      • A
        ab_trader @ThatBlokeDave last edited by ab_trader

        @ThatBlokeDave from my understanding subplot is applicable to whole indicator, observer or data, but not to the particular line. So looks like you may want to have two indicators - trend and signal (which can call trend indicator inside) and plot them with different subplot options.

        • If my answer helped, hit reputation up arrow at lower right corner of the post.
        • Python Debugging With Pdb
        • New to python and bt - check this out
        1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators last edited by

          As pointed out by @ab_trader, subplot only applies to what one could call first class citizens, i.e.: objects that hold lines themselves (Indicators and Observers) Data Feeds are also first class citizens, but they don't support subplot because they are the target of such action (when False)

          Rather than developing a new indicator for that line, a quick solution can be:

          • Creating a SimpleMovingAverage with period=1 of the line in question.
          • Setting plotmaster=datax for that SimpleMovingAverage

          Or ApplyN also with period=1 and a func=lambda x: x[0] (basically the identity function for the unique value in the array). See Docs - Indicators for ApplyN

          Plot master is also documented in Docs - Plotting

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

            Or even better, use the functionality that was specifically created to support this use case: LinePlotterIndicator

            See: Docs - Using Indicators

            1 Reply Last reply Reply Quote 1
            • T
              ThatBlokeDave last edited by

              @ab_trader @backtrader

              Thanks for the suggestions.

              I managed to get the SimpleMovingAverage suggestion working by creating the SMA inside the strategy and feeding it the line.

              I also tried applying the SMA idea inside my custom indicators __init__ method but could not manage to get anything to plot. I guess I cannot plot indicators within indicators (even though the SMA is calculated fine.)

              It would be nice to be able to get the line to plot from within my custom indicator code if possible. So I do not need to create a second indicator in the strategy.

              I also failed in my attempts to get a the LinePlotterIndicator working. I think that is because I am not performing a calculation on the lines themselves. I am simply extracting the date from the line, converting it to a timestamp and calculating Y (price on the chart) from the slope and offset that is calculated during the indicators __init__ from values passed to it.

              Having said that, It is late here and it is likely I am misinterpreting the docs!

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

                @ThatBlokeDave said in Indicators - different subplot values for different lines:

                I also tried applying the SMA idea inside my custom indicators init method but could not manage to get anything to plot. I guess I cannot plot indicators within indicators (even though the SMA is calculated fine.)

                That cannot be done. Strategies plot any indicators directly created by itself. And Indicators plot the lines they have.

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

                  @backtrader

                  Ok noted, thanks.

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