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

To view the implementation of this indicator, see the LEAN GitHub repository.

Using SI Indicator

To create an automatic indicators for WilderSwingIndex, call the SI helper method from the QCAlgorithm class. The SI method creates a WilderSwingIndex object, hooks it up for automatic updates, and returns it so you can used it in your algorithm. In most cases, you should call the helper method in the Initializeinitialize method.

public class WilderSwingIndexAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private WilderSwingIndex _si;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _si = SI(_symbol, 20);
    }

    public override void OnData(Slice data)
    {
        if (_si.IsReady)
        {
            // The current value of _si is represented by itself (_si)
            // or _si.Current.Value
            Plot("WilderSwingIndex", "si", _si);
            
        }
    }
}
class WilderSwingIndexAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.si = self.SI(self.symbol, 20)

    def on_data(self, slice: Slice) -> None:
        if self.si.IsReady:
            # The current value of self.si is represented by self.si.Current.Value
            self.plot("WilderSwingIndex", "si", self.si.Current.Value)
            

The following reference table describes the SI method:

SI()1/1

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

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.

For more information about plotting indicators, see Plotting 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.

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 Updateupdate method with a TradeBar. The indicator will only be ready after you prime it with enough data.

public class WilderSwingIndexAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private WilderSwingIndex _si;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _si = new WilderSwingIndex(20);
    }

    public override void OnData(Slice data)
    {
        if (data.Bars.TryGetValue(_symbol, out var bar))
        {      
            _si.Update(bar);
        }
   
        if (_si.IsReady)
        {
            // The current value of _si is represented by itself (_si)
            // or _si.Current.Value
            Plot("WilderSwingIndex", "si", _si);
            
        }
    }
}
class WilderSwingIndexAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.si = WilderSwingIndex(20)

    def on_data(self, slice: Slice) -> None:
        bar = slice.Bars.get(self.symbol)
        if bar:
            self.si.Update(bar)
        if self.si.IsReady:
            # The current value of self.si is represented by self.si.Current.Value
            self.plot("WilderSwingIndex", "si", self.si.Current.Value)
            

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

public class WilderSwingIndexAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private WilderSwingIndex _si;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _si = new WilderSwingIndex(20);
        RegisterIndicator(_symbol, _si, Resolution.Daily);
    }

    public override void OnData(Slice data)
    {
        if (_si.IsReady)
        {
            // The current value of _si is represented by itself (_si)
            // or _si.Current.Value
            Plot("WilderSwingIndex", "si", _si);
            
        }
    }
}
class WilderSwingIndexAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.si = WilderSwingIndex(20)
        self.RegisterIndicator(self.symbol, self.si, Resolution.Daily)

    def on_data(self, slice: Slice) -> None:
        if self.si.IsReady:
            # The current value of self.si is represented by self.si.Current.Value
            self.plot("WilderSwingIndex", "si", self.si.Current.Value)
            

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.

Visualization

The following image shows plot values of selected properties of WilderSwingIndex using the plotly library.

WilderSwingIndex line plot.

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: