For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Slicing in custom indicator on a different custom indicator gives empty array
-
The code below is where the issue is (I think). My slice is returning an empty array, when I would assume it should be returning the specified array length.
note: period is 1500 bars in the case.
class CustomIndicator(bt.Indicator): def __init__(self): self.addminperiod(self.p.period) self.ac_data_zero = bt.ind.Accum(self.datas[0]) self.ac_data_one = bt.ind.Accum(self.datas[1]) def next(self): time, day = self.get_datetime() last_element = last_element_2 = None if time.hour % 8 == 0 and time.minute == 0 and time.second == 0: self.get_data() # do stuff here unrelated def get_data(self): if self.p.ma_filter: d1 = self.ac_data_zero.get(size=100) # this gives an empty array d2 = self.ac_data_zero[-1] # this gives a float value back d1 = self.ac_data_one.get(size=100) # this gives an empty array d2 = self.ac_data_one[-1] # this gives a float value back
data 0 and data 1 are given through this custom indicator
class NormalizedReturn(bt.Indicator): plotinfo = dict(plot=True) params = (('period', 1), ('ma_filter', False)) alias = ('Return', 'NormalizedReturn',) lines = ('_return',) plotlines = dict(VWAP=dict(alpha=1, linestyle='-', linewidth=2.0)) def __init__(self): # Before super to ensure mixins (right-hand side in subclassing) # can see the assignment operation and operate on the line self.addminperiod(2) # when to deliver values if self.p.ma_filter: close = self.datas[0] close_last_bar = self.datas[0](-1) else: close = self.datas[0].close close_last_bar = self.datas[0].close(-1) norm_return = (close - close_last_bar)/close_last_bar self.lines._return = norm_return
I feel like missing something basic, but sometimes brain no work well.
Any help would be greatly appreciated.
Thanks!