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/

    Does indicators calculates for each new bar?

    Indicators/Strategies/Analyzers
    2
    3
    920
    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.
    • K
      kozlone last edited by

      I'm learning Python in finance with backtrader. Now, I've implemented a simple stragedy for buy/sell assests, but I have no a good understanding of the platform. The documentation is good but still is not clear for me. So, for now there are 2 main questions:

      1. Does indicators calculate the result each time when next method is running? For example, in the init method I'm calculating SMA as follows: self.sma = bt.indicators.SimpleMovingAverage(self.datas[0], period=self.params.maperiod)
        As I can see from the log output the SMA is different each time next is calling.
      2. If the inidcators re-calculates each time next is called may I declare a variable in the __init__ to store the date of the last purchase date?

      I've already implemented this and seems like all is working, but I'm not sure.

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

        Indicators offer you always the latest value, automatically recalculated. It's exactly the point, no interaction from the end user for things which can be automatically done.

        You may declare anything inside __init__ and store anything in your declared variables. It's your code and your way of doing it.

        K 1 Reply Last reply Reply Quote 1
        • K
          kozlone @backtrader last edited by

          @backtrader great, appreciate your help.

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