static public method mathex.lregSlope
Brief
Calculates the linear regression slope of the stream values in the specified range.
Declaration | ||
|
Parameters | |
stream |
The stream of ticks. |
range |
Can be either the range table or the index of the period to calculate the value from. The range can be created using
|
to |
If range parameter is a number, the parameter must contain the index of the period to calculate the value to. |
Details
Please note that all the periods inside the range specified
must conform the following rule: stream:first() <= index <= stream:size() - 1
Example: Calculate the linear regression slope of the last N periods using core.rangeTo method [hide]
local N; local first; local source; function Prepare() ... source = instance.source; first = source:first() + N - 1; ... end ... function Update(period, mode) ... if period >= first then local range = core.rangeTo(period, N); local s; if source:isBar() then s = mathex.lregSlope(source.close, range); else s = mathex.lregSlope(source, range); end end ... end
For the performance reason it is recommended to:
Example: Calculate the linear regression slope of the last N periods using from/to values [hide]
local N; local first; local source; local tsource; function Prepare() ... source = instance.source; if source:isBar() then tsource = source.close; else tsource = source; end first = source:first() + N - 1; ... end ... function Update(period, mode) ... if period >= first then local s; s = mathex.lregSlope(tsource, period - N + 1, period); ... end end