简体   繁体   中英

Does indicators calculates for each new bar? [backtrader]

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.

The answer was given by backtrader admin community:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM