Slope and Linear Regression
Slope of the best fit line is determined by an ordinary least-squares simple linear regression on price. It can be used to help identify trend strength and direction. [Discuss] 💬
// C# usage syntax
IEnumerable<SlopeResult> results =
quotes.GetSlope(lookbackPeriods);
Parameters
lookbackPeriods
int
- Number of periods (N
) for the linear regression. Must be greater than 1.
Historical quotes requirements
You must have at least N
periods of quotes
to cover the warmup periods.
quotes
is a collection of generic TQuote
historical price quotes. It should have a consistent frequency (day, hour, minute, etc). See the Guide for more information.
Response
IEnumerable<SlopeResult>
- This method returns a time series of all available indicator values for the
quotes
provided. - It always returns the same number of elements as there are in the historical quotes.
- It does not return a single incremental indicator value.
- The first
N-1
periods will havenull
values forSlope
since there’s not enough data to calculate. Line
values are only provided for the lastN
periods of your quote history
👉 Repaint warning: the
Line
will be continuously repainted since it is based on the last quote and lookback period.
SlopeResult
Date
DateTime
- Date from evaluated TQuote
Slope
double
- Slope m
of the best-fit line of price
Intercept
double
- Y-Intercept b
of the best-fit line
StdDev
double
- Standard Deviation of price over N
lookback periods
RSquared
double
- R-Squared (R²), aka Coefficient of Determination
Line
decimal
- Best-fit line y
over the last N
periods (i.e. y=mx+b
using last period values)
Utilities
See Utilities and helpers for more information.
Chaining
This indicator may be generated from any chain-enabled indicator or method.
// example
var results = quotes
.GetEma(..)
.GetSlope(..);
Results can be further processed on Slope
with additional chain-enabled indicators.
// example
var results = quotes
.GetSlope(..)
.GetRsi(..);