Wealth-Lab Wiki

API ChartStyles Community Components Community Indicators IndexDefinitions Knowledge Base Misc Optimizers PosSizers Providers Standard Indicators TASC Traders Tips TASCIndicators Tutorial Videos Visualizers


Quick Search
Advanced Search »




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


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.


  • An up-sloping Linear Regression line (LinearRegSlope > 0) indicates that prices have been rising within the regression period, you could open a long position if the rising trend is significant. Use RSquared to determine trend significances.
  • A down-sloping line (LinearRegSlope < 0) indicates prices have been falling within the regression period, you could open a short position if the decline is significant. Use RSquared to determine trend significances.
  • You can open a contrary short-term position to the prevailing trend when the Linear Regression Slope begins to round off at extreme levels.


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.


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( ( lrs20[bar] > 0 ) & ( lrs10[bar] > 0 ) ) SetBarColor( bar, Color.Blue ); if( ( lrs20[bar] < 0 ) & ( lrs10[bar] < 0 ) ) SetBarColor( bar, Color.Red ); } } } }

Important Disclaimer: The information provided by Wealth-Lab is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.  The owner of Wealth-Lab.com assumes no liability resulting from the use of the material contained herein for investment purposes. By using this web site, you agree to the terms of this disclaimer and our Terms of Use.

Used under license from FMR Corp. Copyright 2008 FMR Corp. All rights reserved.

ScrewTurn Wiki. Some of the icons created by FamFamFam.