Indicators - Indexing at __init__()
Can someone help shed some light on a little issue I have? I think I am missing a platform fundamental / concept
Below is a simple example code that demonstrates my issue.
Basically I am trying to create a data feed that is calculated at init and compares the current value of a data feed with the previous value before deciding what to assign to another data.
I seem to be able to get away with it when looking at
data.closebut not with a data feed created during init
class TestInd(bt.Indicator): lines = ('sig',) def __init__(self): self.addminperiod(55) self.data.hlc3 = (self.data.high + self.data.low + self.data.close) / 3 # This works self.data.vd = bt.If(self.data.close >= self.data.close[-1], self.data.volume, -self.data.volume) # This does not self.data.sd = bt.If(self.data.hlc3 >= self.data.hlc3[-1], self.data.volume, -self.data.volume) self.lines.sig = bt.indicators.EMA(self.data.vd, period=34) - bt.indicators.EMA(self.data.vd, period=55)
If someone could jog my memory and remind me what I am doing wrong, that would be great.
@backtrader Thanks! I knew I was forgetting something. Will give it a go.