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

True strength indicator help

  • I'm trying to create the mentioned indicator, but as newb, I have not grasped the concept of how stuff should be done!

    So this is what I'm trying to do:

    class TrueStrengthIndicator(bt.Indicator):
       def __init__(self):
            ema1 = bt.indicators.ExponentialMovingAverage([0] -[-1], period=self.params.lperiod)

    I know that when the first bar is handled, there is no[-1], but how can I handle this.

  • administrators

    See Docs - Platform Concepts and specifically the section Lines: DELAYED indexing

    During the declaration phase the [x] operator makes no sense, because values are not yet there (even if preloading creates the false impression it does)

    The (-x) returns an object which will later deliver the delayed values. In your case: -

    Because you can obviously omit

  • administrators

    It seems a nice indicator. Will get added along small details.

    Should be something like this acoording to Stockcharts - TSI

    class TrueStrengthIndicator(bt.Indicator):
        alias = ('TSI',)
        params = (
            ('period1', 25),
            ('period2', 13),
        lines = ('tsi',)
        def __init__(self):
            pc = -
            smooth1 = bt.ind.EMA(bt.ind.EMA(pc, period=self.p.period1), period=self.p.period2)
            smooth2 = bt.ind.EMA(bt.ind.EMA(abs(pc), period=self.p.period1), period=self.p.period2)
            self.lines.tsi = 100.0 * (smooth1 / smooth2)

  • Thx for the input, as you know now, I have to digest this a little bit to fully understand what you have written.

  • @backtrader
    It works perfectly, thx for the input about delayed indexing! I'm not sure how long it would have taken me to find this!

  • administrators

    Probably the best way is to look at other indicators which are already part of the platform.

    See UpDay (which is nothing else but the definition made by Wilder to later define RSI)

    class UpDay(Indicator):
        lines = ('upday',)
        def __init__(self):
            self.lines.upday = Max( -, 0.0)

    Max is not a typo. Whilst abs can be overridden (for the example above with TSI), max cannot.

    If you look into Ichimoku you can also see line forwarding.

  • @backtrader

Log in to reply