For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Using indicators as parameters of other indicators
-
Hello all.
I want to build an indicator who uses LineBuffers as parameters. It is working when I pass self.datas[0].close for example, but when I use an indicator's line, like rsi.rsi, it is not.
Here is an example of what I want to do :
class DummyInd(bt.Indicator): lines = ('dummy_line',) params = (('src', None),) # src is a LineBuffer def next(self): self.lines.dummy_line[0] = self.params.src[0]
And the strategy :
class DummyStrat(bt.Strategy): def __init__(self): rsi = bt.indicators.RelativeStrenghtIndex() dummy1 = DummyInd(src=self.datas[0].close) data1 = dummy1.dummy_line dummy2 = DummyInd(src=rsi.rsi) data2 = dummy2.dummy_line def log(self): print(f"Data 1 : {self.data1[0]}, Data 2 : {self.data2[0]}") def next(self): self.log()
When I run the DummyStrat, data1 is fine, but data2 is everytime the same value, while RSI has different values over time. I have tried to check values through the next method of DummyInd using print : for self.datas[0].close, the values are fine, but for self.rsi.rsi, it prints the same value for each iteration. Why is it working with datas[0].close, and not with rsi.rsi, when they are supposed to be similar objects ?
Thanks for your help.