Log in to see Cloud of Tags

Wealth-Lab Wiki

Syntax

public RSquared(DataSeries source, int period, string description) public static RSquared Series(DataSeries source, int period) public static double Value(int bar, DataSeries source, int period)

Parameter Description

source The source DataSeries
period Indicator calculation period

Description

RSquared is the Correlation Coefficient squared from Linear Regression. It is used to determine how much of the price action over the specified period can be explained by the regression line, and how much should be attributes to random noise. RSquared ranges from 0 to 1.

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

Interpretation

  • The closer RSquared is to one, the closer prices have fitted to the linear regression line. See the table below. During strong trends, RSquared will remain above 0.5 for an extended period of time. Use the RSquared indicator with LinearRegSlope to determine if a significant trend is in place.
  • Use RSquared for confirmation of the trend. When RSI, Stochastics, CCI and other momentum indicators are in overbought or oversold regions, look for RSquared to show that no statistical trend is in place before taking a contrary trading position.
  • If trading a trend-following system, such as moving average crossover, you can use RSquared to confirm that the trend is statistically significant.

The following table show the RSquared values for a given number of periods for a statistically significant trend to be in place. A 95% confidence means that 95% of the prices can be explained by Linear Regression and 5% by unexplained random noise.

RSquared values for Number of periods 95% confidence
5 0.77
10 0.40
14 0.27
20 0.20
25 0.16
30 0.13
50 0.08
60 0.06
120 0.03

Calculation

RSquared is a rather 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 and returns a percentage of price movement that is explained by the regression line.

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() { // Plot RSquared in order to examine how prices react when they reach different levels. DataSeries r2 = RSquared.Series( Close, 30 ); ChartPane RSquaredPane = CreatePane( 35, true, true ); PlotSeries( RSquaredPane, r2, Color.Red, LineStyle.Solid, 1 ); PlotSeries( RSquaredPane, LinearRegSlope.Series( Close, 30 ), Color.Blue, LineStyle.Solid, 1 ); } } }

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.


ScrewTurn Wiki. Some of the icons created by FamFamFam.