Indicator Reference

True Strength Index

Introduction

This indicator computes the True Strength Index (TSI). The True Strength Index is calculated as explained here: https://school.stockcharts.com/doku.php?id=technical_indicators:True_strength_index Briefly, the calculation has three steps: 1. Smooth the momentum and the absolute momentum by getting an EMA of them (typically of period 25) 2. Double smooth the momentum and the absolute momentum by getting an EMA of their EMA (typically of period 13) 3. The TSI formula itself: divide the double-smoothed momentum over the double-smoothed absolute momentum and multiply by 100 The signal is typically a 7-to-12-EMA of the TSI.

Create Manual Indicators

You can manually create a TrueStrengthIndex indicator, so it doesn’t automatically update. Manual indicators let you update their values with any data you choose. The following reference table describes the TrueStrengthIndex constructor.

TrueStrengthIndex()1/2

            TrueStrengthIndex QuantConnect.Indicators.TrueStrengthIndex (
     *int                signalPeriod,
     *MovingAverageType  signalType
   )
        

Initializes a new instance of the TrueStrengthIndex class using the specified short and long term smoothing periods, and the signal period and type.

TrueStrengthIndex()2/2

            TrueStrengthIndex QuantConnect.Indicators.TrueStrengthIndex (
     string              name,
     *int                signalPeriod,
     *MovingAverageType  signalType
   )
        

Initializes a new instance of the TrueStrengthIndex class using the specified name, the short and long term smoothing periods, and the signal period and type.

The following table shows the MovingAverageType enumeration members and the indicator that implements each one:

MovingAverageTypeUnderlying Indicator
SimpleSimple Moving Average
ExponentialExponential Moving Average
WildersWilder Moving Average
LinearWeightedMovingAverageLinear Weighted Moving Average
DoubleExponentialDouble Exponential Moving Average
TripleExponentialTriple Exponential Moving Average
TriangularTriangular Moving Average
T3T3 Moving Average
KamaKaufman Adaptive Moving Average
HullHull Moving Average
AlmaArnaud Legoux Moving Average

Update Manual Indicators

You can update the indicator automatically or manually.

Automatic Update

To register a manual indicator for automatic updates with the security data, call the RegisterIndicator method.


private TrueStrengthIndex _tsi;

// In Initialize()
_tsi = new TrueStrengthIndex(name);
_tsi.Updated += IndicatorUpdateMethod;

RegisterIndicator(symbol, _tsi, Resolution.Daily);

// In IndicatorUpdateMethod()
if (_tsi.IsReady)
{
    var indicatorValue = _tsi.Current.Value;
}
    
# In Initialize()
self.tsi = TrueStrengthIndex(name)
self.tsi.Updated += self.IndicatorUpdateMethod

self.RegisterIndicator(symbol, self.tsi, Resolution.Daily)

# In IndicatorUpdateMethod()
if self.tsi.IsReady:
    indicator_value = self.tsi.Current.Value

To customize the data that automatically updates the indicator, see Custom Indicator Periods and Custom Indicator Values.

Manual Update

Updating your indicator manually enables you to control when the indicator is updated and what data you use to update it. To manually update the indicator, call the Update method with time/decimal pair. The indicator will only be ready after you prime it with enough data.

    
private TrueStrengthIndex _tsi;
private Symbol symbol;

// In Initialize()
_tsi = new TrueStrengthIndex();
symbol = AddEquity("SPY").Symbol;

// In OnData()
if (data.ContainsKey(_symbol))
{
    _tsi.Update(data[symbol].EndTime, data[symbol].High);
}
if (_tsi.IsReady)
{
    var indicatorValue = _tsi.Current.Value;
}
    
# In Initialize()
self.tsi = TrueStrengthIndex()
self.symbol = self.AddEquity("SPY").Symbol

# In OnData()
if data.ContainsKey(self.symbol):
    self.tsi.Update(data[self.symbol].EndTime, data[self.symbol].High)
if self.tsi.IsReady:
    indicator_value = self.tsi.Current.Value

Create Automatic Indicators

The TSI method creates an TrueStrengthIndex indicator, sets up a consolidator to update the indicator, and then returns the indicator so you can use it in your algorithm.

The following reference table describes the TSI method:

TSI()1/1

            TrueStrengthIndex QuantConnect.Algorithm.QCAlgorithm.TSI (
    Symbol                           symbol,
    *Int32                           longTermPeriod,
    *Int32                           shortTermPeriod,
    *Int32                           signalPeriod,
    *MovingAverageType               signalType,
    *Nullable<Resolution>      resolution,
    *Func<IBaseData, Decimal>  selector
   )
        

Creates a TrueStrengthIndex indicator for the symbol. The indicator will be automatically updated on the given resolution.


The following table shows the MovingAverageType enumeration members and the indicator that implements each one:

MovingAverageTypeUnderlying Indicator
SimpleSimple Moving Average
ExponentialExponential Moving Average
WildersWilder Moving Average
LinearWeightedMovingAverageLinear Weighted Moving Average
DoubleExponentialDouble Exponential Moving Average
TripleExponentialTriple Exponential Moving Average
TriangularTriangular Moving Average
T3T3 Moving Average
KamaKaufman Adaptive Moving Average
HullHull Moving Average
AlmaArnaud Legoux Moving Average

If you don't provide a resolution, it defauls to the security resolution. If you provide a resolution, it must be greater than or equal to the resolution of the security. For instance, if you subscribe to hourly data for a security, you should update its indicator with data that spans 1 hour or longer.

For more information about the selector argument, see Alternative Price Fields.

Get Indicator Values

To get the value of the indicator, use its Current.Value attribute.

private TrueStrengthIndex _tsi;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_tsi = TSI(symbol);

// In OnData()
if (_tsi.IsReady)
{
    var signal = _tsi.Signal.Current.Value;
    var current = _tsi.Current.Value;
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.tsi = self.TSI(symbol)

# In OnData()
if self.tsi.IsReady:
    signal = self.tsi.Signal.Current.Value
    current = self.tsi.Current.Value

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: