Navigation

    Backtrader Community

    • Register
    • 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/

    Referencing the first day in a Data

    Indicators/Strategies/Analyzers
    2
    3
    654
    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.
    • R
      Rstrong last edited by

      Hi,

      I am trying to reference the first day in a data that I have. I want to do this in order to get all time highs and other relevant indicators. This is usually an issue with stocks that have had an IPO after the date my algo filters for. So if I am filtering stocks for the last three years, if something had an IPO a year ago, then I have no way of referencing the first traded day it had.

      I looked through the documentation about backtrader's slicing/indexing and it seems this is something that isnt supported?

      Any suggestions @backtrader or anyone else?

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

        @rstrong said in Referencing the first day in a Data:

        I looked through the documentation about backtrader's slicing/indexing and it seems this is something that isnt supported?

        Following Docs - Platform Concepts and Indexing: 0 and -1 you just have to count backwards. -1 is the previous bar (i.e.: one bar ago), -2 is two bars ago, hence

        firstday = data[len(data) - 1]
        
        R 1 Reply Last reply Reply Quote 1
        • R
          Rstrong @backtrader last edited by

          @backtrader wow that seems so obvious now haha Thanks

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