For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

How to assign arrays to lines?



  • So I'm new to the platform, but I have a question with no answer I can find in the docs.

    I have an indicator function I wrote for use outside of backtrader for my own libraries, but I would like to use it for backtesting on backtrader without having to rewrite it specifically for backtrader. So I am wrapping it. When called, it returns a data structure containing a number of arrays. All of these arrays correspond to custom 'Lines'. When trying to assign the arrays to the indicator lines, all values read 'nan' accessing them within a strategy.

    So the question is boiled down to why does the following not work? How do I get my oracle'd arrays into custom indicator lines?

    {code}
    class CustomIndicator(bt.Indicator):
    lines = ("custom_line", )

    # Price flip is 6 bars
    params = (('period', 6),)
    
    def __init__(self):
        self.addminperiod(self.params.period)
        self.line.custom_line =[0.0] * self.data.close.buflen() # => filled with 'nan's when accessed in a strategy
    

    {code}

    Is there any way to convert an array to a Line object or mass assign its values into a line?

    Would very much appreciate any pointers here



    • clearner code
    class CustomIndicator(bt.Indicator):
    lines = ("custom_line", )
    
    # Price flip is 6 bars
    params = (('period', 6),)
    
    def __init__(self):
        self.addminperiod(self.params.period)
        self.line.custom_line =[0.0] * self.data.close.buflen() # => filled with 'nan's when accessed in a strategy
    

Log in to reply
 

});