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/

    Indexing a list in the same manner as backtrader

    General Code/Help
    2
    2
    740
    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.
    • T
      ThatBlokeDave last edited by

      Hello,
      I have a list of values. In order to be consistent with the platform, I would like to access the most recent value a 0, second most recent as -1 and so on as describes in the concepts section below.

      https://www.backtrader.com/docu/concepts.html#indexing-0-and-1

      How can I implement something similar on my list? I can append to the front of the list to access 0 as the most recent but I am not sure how to get -1 not to point to the end of the list.

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

        Try len(array) - 1 + your_index

        • For 0 that is len(array) - 1 (which is the last element)
        • For -1 that is len(arry) - 1 - 1 (which is the element before the last element)

        And so on

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