Plot vertical line on price chart based on indicator value?



  • 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?


  • administrators

    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


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.