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

What am I doing wrong here?

  • Okay I'm a relatively noob coder but im trying to replicate my manual trading strategy and automate it. In my head from a trader's perspective its so simple but im having a really hard time coding it out. Luckily I got plenty of time.

    What am I doing wrong here;

    import btalib
    class Cstdev(btalib.stddev, btalib.linearreg_slope):
        alias = ('STDDEV',)
        lines = dict(period=14,
        params = (
            ('ddof', 0),
            ('period', 0)
        def __init__(self):
            self.upper_dev1 = btalib.stddev(ddof=0.1, period=2)
            self.upper_dev2 = btalib.stddev(ddof=0.2, period=2)
            self.upper_dev3 = btalib.stddev(ddof=0.3, period=2)
            self.upper_dev4 = btalib.stddev(ddof=0.4, period=2)
            self.lower_dev1 = btalib.stddev(ddof=-0.1, period=2)
            self.lower_dev2 = btalib.stddev(ddof=-0.2, period=2)
            self.lower_dev3 = btalib.stddev(ddof=-0.3, period=2)
            self.lower_dev4 = btalib.stddev(ddof=-0.4, period=2)

    Getting this output:

    btalib.errors.InputsError: One (1) input is at least needed and 0 were provided

  • What I want is to create 4x "bands" using linear regression slope as the "moving average/mean" and stddev as the bands. I don't have to use these indicators if there are easier ways to implement this.

    Thanks in advance!



  • Oh just realized that I'm not supposed to use bta-lib with backtrader, I'll go back to inhereting bt.indicators and ill use ema as a mean just so I can get started.

Log in to reply