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/

    Plot vertical line on price chart based on indicator value?

    Indicators/Strategies/Analyzers
    2
    2
    1404
    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
      cemdev last edited by

      Can this be done? I'd like to plot a vertical line on the price chart based on an indicator value (0 or 1). If it can't be done - can I plot a vertical line on the indicator chart? If so, how?

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

        Plotting a vertical line is actually not there, neither on the data nor on the indicator. Your best bets:

        • Having an observer plotting markers on the data based on the value of an indicator. The BuySell observer looks into buy/sell orders to plot the markers. This would allow you to plot on the data but would be the most ad-hoc solution.

        • Having an indicator plotting markers. For the markers you can look into the BuySell observer or the ParabolicSAR indicator. In your case and since you only want the marker when your indicator is 1, you only assign a value to the indicator when that's the case (and leave the 0 case untouched)

        From BuySell

            plotlines = dict(
                buy=dict(marker='^', markersize=8.0, color='lime',
                         fillstyle='full', ls=''),
                sell=dict(marker='v', markersize=8.0, color='red',
                          fillstyle='full', ls='')
            )
        

        The marker values and options are defined by matplotlib. See how this Blog - Arrows for the BuySell Observer changes the markers for the BuySell observer

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