Supported Indicators

Wilder Swing Index

Introduction

This indicator calculates the Swing Index (SI) as defined by Welles Wilder in his book 'New Concepts in Technical Trading Systems'. SIₜ = 50 * ( N / R ) * ( K / T ) Where: N Equals: Cₜ - Cₜ₋₁ + 0.5 * (Cₜ - Oₜ) + 0.25 * (Cₜ₋₁ - Oₜ₋₁) See R Found by selecting the expression with the largest value and then using the corresponding formula. Expression => Formula |Hₜ - Cₜ₋₁| => |Hₜ - Cₜ| - 0.5 * |Lₜ - Cₜ₋₁| + 0.25 * |Cₜ₋₁ - Oₜ₋₁| |Lₜ - Cₜ₋₁| => |Lₜ - Cₜ| - 0.5 * |Hₜ - Cₜ₋₁| + 0.25 * |Cₜ₋₁ - Oₜ₋₁| |Hₜ - Lₜ| => |Hₜ - Lₜ₋₁| + 0.25 * |Cₜ₋₁ - Oₜ₋₁| See K Found by selecting the larger of the two expressions: |Hₜ - Cₜ₋₁|, |Lₜ - Cₜ₋₁| See T The limit move, or the maximum change in price during the time period for the bar. Passed as limitMove via the constructor. See

Create Manual Indicators

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

WilderSwingIndex()1/2

            WilderSwingIndex QuantConnect.Indicators.WilderSwingIndex (
     string   name,
     decimal  limitMove
   )
        

Initializes a new instance of the WilderSwingIndex class using the specified name.

WilderSwingIndex()2/2

            WilderSwingIndex QuantConnect.Indicators.WilderSwingIndex (
     decimal  limitMove
   )
        

Initializes a new instance of the WilderSwingIndex class using the default name.

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 WilderSwingIndex _si;

// In Initialize()
_si = new WilderSwingIndex(name, limitMove);
_si.Updated += IndicatorUpdateMethod;

RegisterIndicator(symbol, _si, Resolution.Daily);

// In IndicatorUpdateMethod()
if (_si.IsReady)
{
    var indicatorValue = _si.Current.Value;
}
    
# In Initialize()
self.si = WilderSwingIndex(name, limitMove)
self.si.Updated += self.IndicatorUpdateMethod

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

# In IndicatorUpdateMethod()
if self.si.IsReady:
    indicator_value = self.si.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. The indicator will only be ready after you prime it with enough data.

    
private WilderSwingIndex _si;
private Symbol symbol;

// In Initialize()
_si = new WilderSwingIndex(limitMove);
symbol = AddEquity("SPY").Symbol;

// In OnData()
if (data.Bars.ContainsKey(_symbol))
{
    _si.Update(data.Bars[symbol]);
}
if (_si.IsReady)
{
    var indicatorValue = _si.Current.Value;
}
    
# In Initialize()
self.si = WilderSwingIndex(limitMove)
self.symbol = self.AddEquity("SPY").Symbol

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

Create Automatic Indicators

The SI method creates an WilderSwingIndex 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 SI method:

SI()1/1

            WilderSwingIndex QuantConnect.Algorithm.QCAlgorithm.SI (
    Symbol                       symbol,
    Decimal                      limitMove,
    *Nullable<Resolution>  resolution
   )
        

Creates a Wilder Swing Index (SI) indicator for the symbol. The indicator will be automatically updated on the given resolution.


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 WilderSwingIndex _si;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_si = SI(symbol, limitMove);

// In OnData()
if (_si.IsReady)
{
    var current = _si.Current.Value;
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.si = self.SI(symbol, limitMove)

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

Visualization

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

private WilderSwingIndex _si;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_si = SI(symbol, limitMove);

// In OnData()
if (_si.IsReady)
{
    Plot("My Indicators", "wilderswingindex", _si.Current);
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.si = self.SI(symbol, limitMove)

# In OnData()
if self.si.IsReady:
    self.Plot("My Indicators", "wilderswingindex", self.si.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: