recursive indicators
-
Hello community,
it seems a little bit confusing for me if the method nextstart() still needs to be used as written here:
https://medium.com/@danjrod/custom-recursive-indicator-in-python-with-backtrader-1878959ec011I've created a simple PnL indicator:
class MyReturn(bt.Indicator):lines = ('rtn',) params = (('loopback', 30),) def __init__(self): self.lines.rtn = self.data(0)/ self.data(-self.params.loopback) - 1
And surprisingly it works as excepted with nextstart. Any positive externality from my end, or the library is already involving this?
Last, may I kindly ask you about one point where I'm almost lost:
Is there a method that would count the number of bars between the self.data(0) and the buy where the order was executed?Many thanks,
vaclav -
- At the top of each page
For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
-
You have NOT developed a recursive indicator, because you don't use the previous output of your own calculations.
-
That thing does already exist, it is called
PercentageChange
(I do understand that the point was to create do it yourself)
-
Hello, very appreciated. Thank you to help me understand both raised topics as well as the rules (sorry for that).
However, I was misunderstood in the second topic. I'd like to use sumN, however I can't find the actual parameter of order.
My interest is to dynamically update the params period. I'd like to use 4 if I'm 4 bars after the order is being accepted or 10 in the order was accepted in [-10] etc.
"""2018-05-15, BUY EXECUTED, Price: 82.45, Cost: 824.50, Comm 0.00, BARS 1.00
2018-05-15, Close: 81.32, XYZ: -0.11
2018-05-16, Close: 81.67, XYZ: -0.11
2018-05-17, Close: 82.50, XYZ: -0.10"""I'd like to see the no of bars for 2018-05-15 = BARS 2.00, 2018-05-16 = BARS 3.00...
Is that possible? -
Please, disregard the last question and don't lose time with it. I've finally found the information in the quick start (self.bars_executed).