Supported Indicators

Super Trend

Introduction

Super trend indicator. Formula can be found here via the excel file: https://tradingtuitions.com/supertrend-indicator-excel-sheet-with-realtime-buy-sell-signals/

Create Manual Indicators

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

SuperTrend()1/2

            SuperTrend QuantConnect.Indicators.SuperTrend (
     string              name,
     int                 period,
     decimal             multiplier,
     *MovingAverageType  movingAverageType
   )
        

Creates a new SuperTrend indicator using the specified name, period, multiplier and moving average type.

SuperTrend()2/2

            SuperTrend QuantConnect.Indicators.SuperTrend (
     int                 period,
     decimal             multiplier,
     *MovingAverageType  movingAverageType
   )
        

Creates a new SuperTrend indicator using the specified period, multiplier and moving average 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 SuperTrend _str;

// In Initialize()
_str = new SuperTrend(name, period, multiplier);
_str.Updated += IndicatorUpdateMethod;

RegisterIndicator(symbol, _str, Resolution.Daily);

// In IndicatorUpdateMethod()
if (_str.IsReady)
{
    var indicatorValue = _str.Current.Value;
}
    
# In Initialize()
self.str = SuperTrend(name, period, multiplier)
self.str.Updated += self.IndicatorUpdateMethod

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

# In IndicatorUpdateMethod()
if self.str.IsReady:
    indicator_value = self.str.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 a TradeBar, QuoteBar, or an IndicatorDataPoint. The indicator will only be ready after you prime it with enough data.

    
private SuperTrend _str;
private Symbol symbol;

// In Initialize()
_str = new SuperTrend(period, multiplier);
symbol = AddEquity("SPY").Symbol;

// In OnData()
if (data.QuoteBars.ContainsKey(_symbol))
{
    _str.Update(data.QuoteBars[symbol]);
}
if (_str.IsReady)
{
    var indicatorValue = _str.Current.Value;
}
    
# In Initialize()
self.str = SuperTrend(period, multiplier)
self.symbol = self.AddEquity("SPY").Symbol

# In OnData()
if data.QuoteBars.ContainsKey(self.symbol):
    self.str.Update(data.QuoteBars[self.symbol])
if self.str.IsReady:
    indicator_value = self.str.Current.Value

Create Automatic Indicators

The STR method creates an SuperTrend 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 STR method:

STR()1/1

            SuperTrend QuantConnect.Algorithm.QCAlgorithm.STR (
    Symbol                       symbol,
    Int32                        period,
    Decimal                      multiplier,
    *MovingAverageType           movingAverageType,
    *Nullable<Resolution>  resolution
   )
        

Creates a new SuperTrend 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 defaults 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 SuperTrend _str;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_str = STR(symbol, period, multiplier);

// In OnData()
if (_str.IsReady)
{
    var basicUpperBand = _str.BasicUpperBand.Current.Value;
    var basicLowerBand = _str.BasicLowerBand.Current.Value;
    var currentTrailingUpperBand = _str.CurrentTrailingUpperBand.Current.Value;
    var currentTrailingLowerBand = _str.CurrentTrailingLowerBand.Current.Value;
    var current = _str.Current.Value;
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.str = self.STR(symbol, period, multiplier)

# In OnData()
if self.str.IsReady:
    basic_upper_band = self.str.BasicUpperBand.Current.Value
    basic_lower_band = self.str.BasicLowerBand.Current.Value
    current_trailing_upper_band = self.str.CurrentTrailingUpperBand.Current.Value
    current_trailing_lower_band = self.str.CurrentTrailingLowerBand.Current.Value
    current = self.str.Current.Value

Visualization

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

private SuperTrend _str;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_str = STR(symbol, period, multiplier);

// In OnData()
if (_str.IsReady)
{
    Plot("My Indicators", "basicupperband", _str.BasicUpperBand);
    Plot("My Indicators", "basiclowerband", _str.BasicLowerBand);
    Plot("My Indicators", "currenttrailingupperband", _str.CurrentTrailingUpperBand);
    Plot("My Indicators", "currenttrailinglowerband", _str.CurrentTrailingLowerBand);
    Plot("My Indicators", "supertrend", _str.Current);
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.str = self.STR(symbol, period, multiplier)

# In OnData()
if self.str.IsReady:
    self.Plot("My Indicators", "basicupperband", self.str.BasicUpperBand)
    self.Plot("My Indicators", "basiclowerband", self.str.BasicLowerBand)
    self.Plot("My Indicators", "currenttrailingupperband", self.str.CurrentTrailingUpperBand)
    self.Plot("My Indicators", "currenttrailinglowerband", self.str.CurrentTrailingLowerBand)
    self.Plot("My Indicators", "supertrend", self.str.Current)

The following image shows the plot values in a matplotlib plot. To load algorithm plot data into the Research Environment, see Charts.

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: