backtrader.indicators.tsi module

TSI Indicator Module - True Strength Index.

This module provides the TSI (True Strength Index) indicator developed by William Blau for measuring momentum with double smoothing.

Classes:

TrueStrengthIndicator: TSI indicator (alias: TSI).

Example

class MyStrategy(bt.Strategy):
def __init__(self):

self.tsi = bt.indicators.TSI(self.data.close, period1=25, period2=13)

def next(self):
if self.tsi[0] > 0:

self.buy()

class backtrader.indicators.tsi.TrueStrengthIndicator[source]

Bases: Indicator

The True Strength Indicators was first introduced in Stocks & Commodities Magazine by its author William Blau. It measures momentum with a double exponential (default) of the prices.

It shows divergence if the extremes keep on growign but closing prices do not in the same manner (distance to the extremes grows)

Formula:
  • price_change = close - close(pchange periods ago)

  • sm1_simple = EMA(price_close_change, period1)

  • sm1_double = EMA(sm1_simple, period2)

  • sm2_simple = EMA(abs(price_close_change), period1)

  • sm2_double = EMA(sm2_simple, period2)

  • tsi = 100.0 * sm1_double / sm2_double

See:

Params

  • period1: the period for the first smoothing

  • period2: the period for the second smoothing

  • pchange: the lookback period for the price change

  • _movav: the moving average to apply for the smoothing

alias = ('TSI',)
__init__(*args, **kwargs)
nextstart()[source]

Seed TSI calculation on first valid bar.

Initializes smoothed momentum values with first price change.

next()[source]

Calculate TSI for the current bar.

Applies double smoothing to price change and absolute price change, then computes the ratio as a percentage.

once(start, end)[source]

Calculate TSI in runonce mode.

Computes double-smoothed momentum values and TSI ratio across all bars.

frompackages = ()
packages = ()