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'.
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 Initialize
method.
public class WilderSwingIndexAlgorithm : QCAlgorithm { private Symbol _symbol; private WilderSwingIndex _si; public override void Initialize() { _symbol = AddEquity("SPY", Resolution.Daily).Symbol; _si = SI("SPY", 20); } public override void OnData(Slice data) { if (_si.IsReady) { Plot("WilderSwingIndex", "si", _si); } } }
class WilderSwingIndexAlgorithm(QCAlgorithm): def Initialize(self) -> None: self.symbol = self.AddEquity("SPY", Resolution.Daily).Symbol self.si = self.SI("SPY", 20) def OnData(self, slice: Slice) -> None: if self.si.IsReady: 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 Update
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.TryGeValue(_symbol, out var bar)) { _si.Update(bar); } if (_si.IsReady) { Plot("WilderSwingIndex", "si", _si); } } }
class WilderSwingIndexAlgorithm(QCAlgorithm): def Initialize(self) -> None: self.symbol = self.AddEquity("SPY", Resolution.Daily).Symbol self.si = WilderSwingIndex(20) def OnData(self, slice: Slice) -> None: bar = data.Bars.get(self.symbol) if bar: self.si.Update(bar) if self.si.IsReady: 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) { 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 OnData(self, slice: Slice) -> None: if self.si.IsReady: 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 WilderSwingInde
class using the specified name.
WilderSwingIndex()2/2
WilderSwingIndex QuantConnect.Indicators.WilderSwingIndex (
decimal
limitMove
)
Initializes a new instance of the WilderSwingInde
class using the default name.
Visualization
The following image shows plot values of selected properties of WilderSwingIndex
using the plotly library.
