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/

    How to calculate the highest close value in a period except current close value?

    General Code/Help
    2
    2
    295
    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.
    • G
      G_will last edited by

      Now I use this method:

      # include current close value
      btind.Highest(self.data.close, period=n)
      
      # except current close value
      btind.Highest(self.data.close(-1), period=n-1)
      

      Is there a better method?

      B 1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators @G_will last edited by

        @g_will said in How to calculate the highest close value in a period except current close value?:

        # except current close value
        btind.Highest(self.data.close(-1), period=n-1)
        

        close(-1) excludes the current close from the calculation, so it would seem to fit your purpose perfectly. Whether you use n or n - 1 is really up to your expectation of how many data points have to be included.

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors