List of active indicators into an OR() to make a global indicator
-
My backtesting system generates a list of values external to BT that would be the levels of interest to generate a CrossUp or CrossDown signal. There can be a varying number of levels on a given day as the levels are generated from a machine learning output.
I would like to do something like this:# Dictionary of levels, structure is somewhat arbitrary levels = {'level1': 100.00, 'level2' : 101.00}
In BT init, I would like to instantiate a CrossUp for each of the levels:
for level in levels: indicator_name = 'primary_ind_' + levels.index(level) indicator_name = CrossUp(self.data.Close, level)
and i suspect this will work.
However, my real goal is to then combine all of the indicators together into an ANY or OR indicator, but i fail for two reasons:
- I cant find a way to get a list from BT of the instantiated indicators
- I cant see how to pass a list to the backtrader OR function
# This is what i want to do, but cant do secondary_ind = bt.OR('list of indictors')
Has anyone managed this or something similar? The challenge seems to be the changing number of indicators from run to run, if it was the same each time I think I could do it with my smooth brain by hardcoding each one in the OR function.