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/

    Buying N day high for trend following

    Indicators/Strategies/Analyzers
    3
    3
    1909
    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.
    • M
      mpgentleman last edited by backtrader

      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,

      1 Reply Last reply Reply Quote 0
      • RandyT
        RandyT last edited by

        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)
        
        1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators last edited by

          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(...)
          ...
          
          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors