Contents
Indicator Reference
Regression Channel
Introduction
The Regression Channel indicator extends the
Create Manual Indicators
You can manually create a RegressionChannel
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 RegressionChannel
constructor.
RegressionChannel()1/2
RegressionChannel QuantConnect.Indicators.RegressionChannel (string
name,int
period,decimal
k )
Initializes a new instance of the RegressionChannel
class.
RegressionChannel()2/2
RegressionChannel QuantConnect.Indicators.RegressionChannel (int
period,decimal
k )
Initializes a new instance of the LeastSquaresMovingAverage
class.
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 RegressionChannel _rc; // In Initialize() _rc = new RegressionChannel(name, period, k); _rc.Updated += IndicatorUpdateMethod; RegisterIndicator(symbol, _rc, Resolution.Daily); // In IndicatorUpdateMethod() if (_rc.IsReady) { var indicatorValue = _rc.Current.Value; }
# In Initialize() self.rc = RegressionChannel(name, period, k) self.rc.Updated += self.IndicatorUpdateMethod self.RegisterIndicator(symbol, self.rc, Resolution.Daily) # In IndicatorUpdateMethod() if self.rc.IsReady: indicator_value = self.rc.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 RegressionChannel _rc; private Symbol symbol; // In Initialize() _rc = new RegressionChannel(period, k); symbol = AddEquity("SPY").Symbol; // In OnData() if (data.ContainsKey(_symbol)) { _rc.Update(data[symbol].EndTime, data[symbol].High); } if (_rc.IsReady) { var indicatorValue = _rc.Current.Value; }
# In Initialize() self.rc = RegressionChannel(period, k) self.symbol = self.AddEquity("SPY").Symbol # In OnData() if data.ContainsKey(self.symbol): self.rc.Update(data[self.symbol].EndTime, data[self.symbol].High) if self.rc.IsReady: indicator_value = self.rc.Current.Value
Create Automatic Indicators
The RC method creates an RegressionChannel 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 RC
method:
RC()1/1
RegressionChannel QuantConnect.Algorithm.QCAlgorithm.RC (Symbol
symbol,Int32
period,Decimal
k,*Nullable<Resolution>
resolution,*Func<IBaseData, Decimal>
selector )
Creates a new RegressionChannel indicator which will compute the LinearRegression, UpperChannel and LowerChannel lines, the intercept and slope
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 RegressionChannel _rc; // In Initialize() var symbol = AddEquity("SPY").Symbol; _rc = RC(symbol, period, k); // In OnData() if (_rc.IsReady) { var linearRegression = _rc.LinearRegression.Current.Value; var upperChannel = _rc.UpperChannel.Current.Value; var lowerChannel = _rc.LowerChannel.Current.Value; var intercept = _rc.Intercept.Current.Value; var slope = _rc.Slope.Current.Value; var current = _rc.Current.Value; }
# In Initialize() symbol = self.AddEquity("SPY").Symbol self.rc = self.RC(symbol, period, k) # In OnData() if self.rc.IsReady: linear_regression = self.rc.LinearRegression.Current.Value upper_channel = self.rc.UpperChannel.Current.Value lower_channel = self.rc.LowerChannel.Current.Value intercept = self.rc.Intercept.Current.Value slope = self.rc.Slope.Current.Value current = self.rc.Current.Value
Visualization
To plot indicator values, in the OnData
event handler, call the Plot
method.
private RegressionChannel _rc; // In Initialize() var symbol = AddEquity("SPY").Symbol; _rc = RC(symbol, period, k); // In OnData() if (_rc.IsReady) { Plot("My Indicators", "linearregression", _rc.LinearRegression); Plot("My Indicators", "upperchannel", _rc.UpperChannel); Plot("My Indicators", "lowerchannel", _rc.LowerChannel); Plot("My Indicators", "intercept", _rc.Intercept); Plot("My Indicators", "slope", _rc.Slope); Plot("My Indicators", "regressionchannel", _rc.Current); }
# In Initialize() symbol = self.AddEquity("SPY").Symbol self.rc = self.RC(symbol, period, k) # In OnData() if self.rc.IsReady: self.Plot("My Indicators", "linearregression", self.rc.LinearRegression) self.Plot("My Indicators", "upperchannel", self.rc.UpperChannel) self.Plot("My Indicators", "lowerchannel", self.rc.LowerChannel) self.Plot("My Indicators", "intercept", self.rc.Intercept) self.Plot("My Indicators", "slope", self.rc.Slope) self.Plot("My Indicators", "regressionchannel", self.rc.Current)
For more information about plotting indicators, see Plotting Indicators.