For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Unable to get LinePlotterIndicator to display



  • I have a custom indicator that simply checks if a value is above or below a threshold.

    class AboveBelow(bt.Indicator):
        lines = ('above', 'below')
        
        params = (('above', 80), ('below', 20))
        
        plotinfo = dict(
            # Add extra margins above and below the 1s and -1s
            plotymargin=0.15,
    
            # Simplify the y scale to 1.0 and -1.0
            plotyticks=[1, 0])
    
        def __init__(self):
            self.l.above = self.data > self.p.above
            self.l.below = self.data < self.p.below
            bt.LinePlotterIndicator(self.l.above, name='Above')
            bt.LinePlotterIndicator(self.l.below, name='Below')
    

    But I am not able to get these values to display on the cerebro.plot(). I read in the docs that because of the use of > and < the lines won't just plot automatically and that you need to use LinePlotterIndicator however no matter what I try I can't get it to show on the plot.


  • administrators

    This is because LinePlotterIndicator is meant to be used directly inside a Strategy. If you instantiate it inside another indicator ... it's not directly under the hierarchy of the strategy and won't be displayed (if it were, indicators on indicators on indicators would also be displayed and that makes no sense)

    In any case, what's the expected goal in this usage?

    Because above and below will automatically be displayed when you instantiate AboveBelow in a Strategy subclass.



  • @backtrader My goal here is to have an indicator that will show on the plot that has a high/low signal when another line crosses above or below a particular threshold.

    @backtrader said in Unable to get LinePlotterIndicator to display:

    Because above and below will automatically be displayed when you instantiate AboveBelow in a Strategy subclass.

    What exactly do you mean by this? If I remove the two lines with bt.LinePlotterIndicator and just leave the two lines above those I do not see anything plotted. My understanding from the docs is that this is the expected behavior. Is there something I am missing to get this to display on the plot?


  • administrators

    The lines of all other indicators do actually get plotted, there is no reason why above and below to not get plotted.

    @sfkiwi said in Unable to get LinePlotterIndicator to display:

    But I am not able to get these values to display on the cerebro.plot(). I read in the docs that because of the use of > and < the lines won't just plot automatically

    This is when you make a comparison and is not assigned to a line. In that case one uses LinePlotterIndicator to fake an indicator that holds the resulting operation of the comparison.

    Don't you think that an actual plot (you posted an example in the other thread) could help?