Contents
Indicator Reference
Swiss Army Knife
Create Manual Indicators
You can manually create a SwissArmyKnife
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 SwissArmyKnife
constructor.
SwissArmyKnife()1/2
SwissArmyKnife QuantConnect.Indicators.SwissArmyKnife (int
period,double
delta,SwissArmyKnifeTool
tool )
Swiss Army Knife indicator by John Ehlers.
SwissArmyKnife()2/2
SwissArmyKnife QuantConnect.Indicators.SwissArmyKnife (string
name,int
period,double
delta,SwissArmyKnifeTool
tool )
Swiss Army Knife indicator by John Ehlers.
The SwissArmyKnifeTool
enumeration has the following members:
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 SwissArmyKnife _swiss; // In Initialize() _swiss = new SwissArmyKnife(name, period, delta, tool); _swiss.Updated += IndicatorUpdateMethod; RegisterIndicator(symbol, _swiss, Resolution.Daily); // In IndicatorUpdateMethod() if (_swiss.IsReady) { var indicatorValue = _swiss.Current.Value; }
# In Initialize() self.swiss = SwissArmyKnife(name, period, delta, tool) self.swiss.Updated += self.IndicatorUpdateMethod self.RegisterIndicator(symbol, self.swiss, Resolution.Daily) # In IndicatorUpdateMethod() if self.swiss.IsReady: indicator_value = self.swiss.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 SwissArmyKnife _swiss; private Symbol symbol; // In Initialize() _swiss = new SwissArmyKnife(period, delta, tool); symbol = AddEquity("SPY").Symbol; // In OnData() if (data.ContainsKey(_symbol)) { _swiss.Update(data[symbol].EndTime, data[symbol].High); } if (_swiss.IsReady) { var indicatorValue = _swiss.Current.Value; }
# In Initialize() self.swiss = SwissArmyKnife(period, delta, tool) self.symbol = self.AddEquity("SPY").Symbol # In OnData() if data.ContainsKey(self.symbol): self.swiss.Update(data[self.symbol].EndTime, data[self.symbol].High) if self.swiss.IsReady: indicator_value = self.swiss.Current.Value
Create Automatic Indicators
The SWISS method creates an SwissArmyKnife 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 SWISS
method:
SWISS()1/1
SwissArmyKnife QuantConnect.Algorithm.QCAlgorithm.SWISS (Symbol
symbol,Int32
period,Double
delta,SwissArmyKnifeTool
tool,*Nullable<Resolution>
resolution,*Func<IBaseData, Decimal>
selector )
Creates Swiss Army Knife transformation for the symbol. The indicator will be automatically updated on the given resolution.
The SwissArmyKnifeTool
enumeration has the following members:
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 SwissArmyKnife _swiss; // In Initialize() var symbol = AddEquity("SPY").Symbol; _swiss = SWISS(symbol, period, delta, tool); // In OnData() if (_swiss.IsReady) { var current = _swiss.Current.Value; }
# In Initialize() symbol = self.AddEquity("SPY").Symbol self.swiss = self.SWISS(symbol, period, delta, tool) # In OnData() if self.swiss.IsReady: current = self.swiss.Current.Value
Visualization
To plot indicator values, in the OnData
event handler, call the Plot
method.
private SwissArmyKnife _swiss; // In Initialize() var symbol = AddEquity("SPY").Symbol; _swiss = SWISS(symbol, period, delta, tool); // In OnData() if (_swiss.IsReady) { Plot("My Indicators", "swissarmyknife", _swiss.Current); }
# In Initialize() symbol = self.AddEquity("SPY").Symbol self.swiss = self.SWISS(symbol, period, delta, tool) # In OnData() if self.swiss.IsReady: self.Plot("My Indicators", "swissarmyknife", self.swiss.Current)
For more information about plotting indicators, see Plotting Indicators.