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

Help plotting a custom indicator's line object on the main plot



  • I've managed to get a custom indicator to work. I'm able to interact with it in my next(self) function.
    Only problem is, it will not plot on the main plot, it only plots on a subplot (I really want it on the main plot).
    I feel like I'm losing my mind over something so simple. Help me please.
    Code below:

    import backtrader as bt
    
    class indmax(bt.Indicator):
        lines = ('max')
        params = (('period', 250),)
        
        def __init__(self):
            # pulled this bit from the backtrader stochastic rsi source code
            hh = bt.indicators.Highest(self.data, period=self.p.period)
            self.lines.max = hh
    

    In my strategy, I reference the custom indicator like so:

    class HelpMeStrategy(bt.Strategy):
        params = (('maxperiod', 250),)
    
        def __init__(self): 
            self.stratmax= indmax(self.datas[0], period=self.params.maxperiod)
    

    Doing the these steps with the existing backtrader sma indicator yields a plot on the main plot by default, but not my stupid custom indicator.

    Thanks,
    Sam


  • administrators

    Docs - Plotting - subplot



  • BOY, do I feel stupid. Thank you Mr. Backtrader! :)


Log in to reply
 

});