Indicator Reference

Schaff Trend Cycle

Introduction

This indicator creates the Schaff Trend Cycle

Create Manual Indicators

You can manually create a SchaffTrendCycle 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 SchaffTrendCycle constructor.

SchaffTrendCycle()1/2

            SchaffTrendCycle QuantConnect.Indicators.SchaffTrendCycle (
     *int                slowPeriod,
     *MovingAverageType  type
   )
        

https://www.tradingpedia.com/forex-trading-indicators/schaff-trend-cycle.

SchaffTrendCycle()2/2

            SchaffTrendCycle QuantConnect.Indicators.SchaffTrendCycle (
     string             name,
     int                slowPeriod,
     MovingAverageType  type
   )
        

Creates a new schaff trend cycle with the specified parameters.

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 SchaffTrendCycle _stc;

// In Initialize()
_stc = new SchaffTrendCycle(name, fastPeriod, slowPeriod, cyclePeriod, type);
_stc.Updated += IndicatorUpdateMethod;

RegisterIndicator(symbol, _stc, Resolution.Daily);

// In IndicatorUpdateMethod()
if (_stc.IsReady)
{
    var indicatorValue = _stc.Current.Value;
}
    
# In Initialize()
self.stc = SchaffTrendCycle(name, fastPeriod, slowPeriod, cyclePeriod, type)
self.stc.Updated += self.IndicatorUpdateMethod

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

# In IndicatorUpdateMethod()
if self.stc.IsReady:
    indicator_value = self.stc.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 SchaffTrendCycle _stc;
private Symbol symbol;

// In Initialize()
_stc = new SchaffTrendCycle(fastPeriod, slowPeriod, cyclePeriod, type);
symbol = AddEquity("SPY").Symbol;

// In OnData()
if (data.ContainsKey(_symbol))
{
    _stc.Update(data[symbol].EndTime, data[symbol].High);
}
if (_stc.IsReady)
{
    var indicatorValue = _stc.Current.Value;
}
    
# In Initialize()
self.stc = SchaffTrendCycle(fastPeriod, slowPeriod, cyclePeriod, type)
self.symbol = self.AddEquity("SPY").Symbol

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

Create Automatic Indicators

The STC method creates an SchaffTrendCycle 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 STC method:

STC()1/1

            SchaffTrendCycle QuantConnect.Algorithm.QCAlgorithm.STC (
    Symbol                           symbol,
    Int32                            cyclePeriod,
    Int32                            fastPeriod,
    Int32                            slowPeriod,
    *MovingAverageType               movingAverageType,
    *Nullable<Resolution>      resolution,
    *Func<IBaseData, Decimal>  selector
   )
        

Creates a new Schaff Trend Cycle indicator


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 SchaffTrendCycle _stc;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_stc = STC(symbol, cyclePeriod, fastPeriod, slowPeriod);

// In OnData()
if (_stc.IsReady)
{
    var current = _stc.Current.Value;
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.stc = self.STC(symbol, cyclePeriod, fastPeriod, slowPeriod)

# In OnData()
if self.stc.IsReady:
    current = self.stc.Current.Value

Visualization

To plot indicator values, in the OnData event handler, call the Plot method.

private SchaffTrendCycle _stc;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_stc = STC(symbol, cyclePeriod, fastPeriod, slowPeriod);

// In OnData()
if (_stc.IsReady)
{
    Plot("My Indicators", "schafftrendcycle", _stc.Current);
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.stc = self.STC(symbol, cyclePeriod, fastPeriod, slowPeriod)

# In OnData()
if self.stc.IsReady:
    self.Plot("My Indicators", "schafftrendcycle", self.stc.Current)

For more information about plotting indicators, see Plotting Indicators.

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: