Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    List of active indicators into an OR() to make a global indicator

    Indicators/Strategies/Analyzers
    1
    1
    14
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      stevenm100 last edited by

      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:

      1. I cant find a way to get a list from BT of the instantiated indicators
      2. 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.

      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors