Buying N day high for trend following



  • I'm having trouble with a simple trend following strategy of buying 55 day highs. I tried using something similar to the Ichimoku indicator.

    hi_bar = Highest(self.data.high, period=self.p.period)
    

    I get an error that Highest is not recognized.

    Thanks,



  • Seeing the code would make this easier to answer, but you are likely not importing these classes into your strategy code.

    Something as follows:

    import backtrader as bt
    import backtrader.indicators as btind
    
    hi_bar = btind.Highest(self.data.high, period=self.p.period)
    

  • administrators

    The code by @randyt is 100% ok. Some versions ago and to reduce the number of needed imports, the main package gives direct access to subpackages, so you may also do

    import backtrader as bt
    
    ...
       hi_bar = bt.indicators.Highest(...)
    ...
    

    of for even less typing

    import backtrader as bt
    
    ...
       hi_bar = bt.ind.Highest(...)
    ...
    

Log in to reply
 

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