LinearRegSlope

Modified on 2010/08/25 10:53 by Eugene — Categorized as: Standard Indicators

Syntax

public LinearRegSlope(DataSeries ds, int period, string description) public static LinearRegSlope Series(DataSeries ds, int period) public static double Value(int bar, DataSeries ds, int period)

Parameter Description

ds Price series
period Indicator calculation period

Description

Linear Regression Slope returns the slope of the Linear Regression line (see LinearReg) of the DataSeries ds for the specified period. It looks at the prices for the number of specified periods and finds a straight line which best fits all the prices. The slope of this straight line is returned. Use the slope to determine if the trend is up (positive value) or down (negative value), as well as the general strength of the trend. It shows how much the prices are expected to change over time.

Linear Regression Slope indicator is a statistical indicator. Other indicators in the same class are LinearReg, StdError, RSquared and StdDev.

Interpretation


Calculation

Linear Regression is a somewhat complex statistical calculation. It uses the least square method to fit a trendline to the data by minimizing the distance between the price and the Linear Regression trendline. The slope of this Linear Regression trendline (given by LinearReg) is the value return by the LinearRegSlope indicator.

Example

using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { /* Minor up and down trends highlighted by confirmation of 2 linear regression lines */

DataSeries lrs20 = LinearRegSlope.Series( Close, 20 ); DataSeries lrs10 = LinearRegSlope.Series( Close, 10 ); ChartPane LinRegSlopePane = CreatePane( 50, true, true ); PlotSeries( LinRegSlopePane, lrs20, Color.Black, WealthLab.LineStyle.Solid, 1 ); PlotSeries( LinRegSlopePane, lrs10, Color.Blue, WealthLab.LineStyle.Solid, 1 ); SetBarColors( Color.Black, Color.Black );

for(int bar = 20; bar < Bars.Count; bar++) { if( ( lrs20bar > 0 ) & ( lrs10bar > 0 ) ) SetBarColor( bar, Color.Blue ); if( ( lrs20bar < 0 ) & ( lrs10bar < 0 ) ) SetBarColor( bar, Color.Red ); } } } }