Contents
Indicator Reference
Relative Vigor Index
Introduction
The Relative Vigor Index (RVI) compares the ratio of the closing price of a security to its trading range. For illustration, let:
Create Manual Indicators
You can manually create a RelativeVigorIndex
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 RelativeVigorIndex
constructor.
RelativeVigorIndex()1/3
RelativeVigorIndex QuantConnect.Indicators.RelativeVigorIndex ( )
A signal line which behaves like a slowed version of the RVI.
RelativeVigorIndex()2/3
RelativeVigorIndex QuantConnect.Indicators.RelativeVigorIndex (int
period,MovingAverageType
type )
Initializes a new instance of the RelativeVigorIndex
(RVI) class.
RelativeVigorIndex()3/3
RelativeVigorIndex QuantConnect.Indicators.RelativeVigorIndex (string
name,int
period,*MovingAverageType
type )
Initializes a new instance of the RelativeVigorIndex
(RVI) class.
The following table shows the MovingAverageType
enumeration members and the indicator that implements each one:
MovingAverageType | Underlying Indicator |
---|---|
Simple | Simple Moving Average |
Exponential | Exponential Moving Average |
Wilders | Wilder Moving Average |
LinearWeightedMovingAverage | Linear Weighted Moving Average |
DoubleExponential | Double Exponential Moving Average |
TripleExponential | Triple Exponential Moving Average |
Triangular | Triangular Moving Average |
T3 | T3 Moving Average |
Kama | Kaufman Adaptive Moving Average |
Hull | Hull Moving Average |
Alma | Arnaud 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 RelativeVigorIndex _rvi; // In Initialize() _rvi = new RelativeVigorIndex(name, period); _rvi.Updated += IndicatorUpdateMethod; RegisterIndicator(symbol, _rvi, Resolution.Daily); // In IndicatorUpdateMethod() if (_rvi.IsReady) { var indicatorValue = _rvi.Current.Value; }
# In Initialize() self.rvi = RelativeVigorIndex(name, period) self.rvi.Updated += self.IndicatorUpdateMethod self.RegisterIndicator(symbol, self.rvi, Resolution.Daily) # In IndicatorUpdateMethod() if self.rvi.IsReady: indicator_value = self.rvi.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 RelativeVigorIndex _rvi; private Symbol symbol; // In Initialize() _rvi = new RelativeVigorIndex(period); symbol = AddEquity("SPY").Symbol; // In OnData() if (data.QuoteBars.ContainsKey(_symbol)) { _rvi.Update(data.QuoteBars[symbol]); } if (_rvi.IsReady) { var indicatorValue = _rvi.Current.Value; }
# In Initialize() self.rvi = RelativeVigorIndex(period) self.symbol = self.AddEquity("SPY").Symbol # In OnData() if data.QuoteBars.ContainsKey(self.symbol): self.rvi.Update(data.QuoteBars[self.symbol]) if self.rvi.IsReady: indicator_value = self.rvi.Current.Value
Create Automatic Indicators
The RVI method creates an RelativeVigorIndex 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 RVI
method:
RVI()1/1
RelativeVigorIndex QuantConnect.Algorithm.QCAlgorithm.RVI (Symbol
symbol,Int32
period,*MovingAverageType
movingAverageType,*Nullable<Resolution>
resolution,*Func<IBaseData, TradeBar>
selector )
Creates a new RelativeVigorIndex indicator.
The following table shows the MovingAverageType
enumeration members and the indicator that implements each one:
MovingAverageType | Underlying Indicator |
---|---|
Simple | Simple Moving Average |
Exponential | Exponential Moving Average |
Wilders | Wilder Moving Average |
LinearWeightedMovingAverage | Linear Weighted Moving Average |
DoubleExponential | Double Exponential Moving Average |
TripleExponential | Triple Exponential Moving Average |
Triangular | Triangular Moving Average |
T3 | T3 Moving Average |
Kama | Kaufman Adaptive Moving Average |
Hull | Hull Moving Average |
Alma | Arnaud Legoux Moving Average |
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 RelativeVigorIndex _rvi; // In Initialize() var symbol = AddEquity("SPY").Symbol; _rvi = RVI(symbol, period); // In OnData() if (_rvi.IsReady) { var signal = _rvi.Signal.Current.Value; var current = _rvi.Current.Value; }
# In Initialize() symbol = self.AddEquity("SPY").Symbol self.rvi = self.RVI(symbol, period) # In OnData() if self.rvi.IsReady: signal = self.rvi.Signal.Current.Value current = self.rvi.Current.Value
Visualization
To plot indicator values, in the OnData
event handler, call the Plot
method.
private RelativeVigorIndex _rvi; // In Initialize() var symbol = AddEquity("SPY").Symbol; _rvi = RVI(symbol, period); // In OnData() if (_rvi.IsReady) { Plot("My Indicators", "signal", _rvi.Signal); Plot("My Indicators", "relativevigorindex", _rvi.Current); }
# In Initialize() symbol = self.AddEquity("SPY").Symbol self.rvi = self.RVI(symbol, period) # In OnData() if self.rvi.IsReady: self.Plot("My Indicators", "signal", self.rvi.Signal) self.Plot("My Indicators", "relativevigorindex", self.rvi.Current)
For more information about plotting indicators, see Plotting Indicators.