Skip to content

Plot indicators dynamically computed in next() #87

Closed
@sidsidsidsid

Description

@sidsidsidsid

First, great product. I've been looking for something like this for a while. What are your future plans/direction with the product?

Second, my question is an extension of issue #74. I understand how to add indicators. But, is there a way that their results are added to the bt.plot()? For example below; I would like indicator1 and indicator2 plotted. Note: my indicators do not pass in any values created in the init() method.

I thought of wrapping them in the self.I(), but as stated above, they are using data created from data generated in the init(). Is there a way to get c_var and s_var plotted using bt.plot().

def myIndicator1():
   value = ...
   return value

def myIndicator2():
   value = ...
   return value

class SmaCross(Strategy):
    def init(self):
        self.sma1 = self.I(SMA, self.data.Close, self.n1)
        self.sma2 = self.I(SMA, self.data.Close, self.n2)
    
    def next(self):
        c_var = (self.sma1 * 345).std() - 5
        out = myIndicator( c_var)
        s_var = out.std()
        results = myIndicator2(s_var)

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions