> For the complete documentation index, see [llms.txt](https://chartschool.stockcharts.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chartschool.stockcharts.com/table-of-contents/technical-indicators-and-overlays/technical-indicators/linear-regression-r2.md).

# Linear Regression R2

## What Is the Linear Regression R2 Indicator?

The Linear Regression R2 (LR-R2 indicator uses linear regression techniques to determine how closely price data adheres to a trend line. In other words, it determines whether a security is trending or not.

<figure><img src="https://436553459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FERtrZrZOhufFzk6ZQO4B%2Fuploads%2FamcSZCVBdG6M88YvuKcZ%2Flrr2example.png?alt=media&amp;token=3222a1f6-d724-4a8c-a65d-170bb572791b" alt=""><figcaption></figcaption></figure>

It is primarily used to decide whether to trade at all. If you're a trend trader, you want to trade when price is trending. If you prefer to get in and out of trades more frequently than a trend trader, you'd prefer to trade in a non-trending market.

## Calculating LR-R2

Linear Regression R2 is based on a linear regression (line of best fit), and determines how closely individual data points on a price chart follow that straight line. The exact formula of linear regression is beyond the scope of this article, but after the linear regression is calculated, the rest of the formula is simpler.

The first step is to take all the data points in the specified lookback period, and determine the linear regression value based on that data. Next, average the data points in that lookback period. Both the linear regression value and the average price for each data point will be used in the calculation of LR-R2.     &#x20;

```
  Deviation from Regression Line = (Close - Regression Line Value) squared
  Deviation from Average Price = (Close - Average Price) squared
  
  Linear Regression R2 = 1 - (Dev. from Regression Line / Dev. from Average Price)		
```

It compares the amount of deviation from the regression line to the amount of deviation from the average price over the timeframe, in order to determine how much of the total variation in price can be explained by the fact that the price action is following a trend.

## Interpreting LR-R2

The interpretation of the Linear Regression R2 indicator is very straightforward. It's an oscillator that moves between zero and one. When it's at zero, it indicates a lack of trend and when it's at one, it indicates a strong trend.&#x20;

### Identifying Strong Trends

LR-R2 values near 1.0 indicate price action that follows a very straight line.

The chart below shows Raytheon (RTX) in a somewhat messy uptrend from early June to August, followed by a steep linear downtrend from August to October. Note that LR-R2 is at or near the top of its range for most of that downtrend, because the price bars are in such a straight line. The uptrend, on the other hand, is full of pullbacks, trading ranges, and gaps up. The LR-R2 reflects this, with a much choppier line that peaks short of the top and drops multiple times over the length of the uptrend.

<figure><img src="https://436553459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FERtrZrZOhufFzk6ZQO4B%2Fuploads%2FfTJSkxTy3EPcBDmoj1Qv%2Flrr2strongtrend.png?alt=media&amp;token=0c2d2814-182b-48f4-a48b-1192fc681ada" alt=""><figcaption><p>LR-R2 values near 1.0 indicate a strong trend.</p></figcaption></figure>

Note that the LR-R2 value is high even in a downtrend. This indicator does not measure the *direction* of the trend - only whether the security is trending or not.

### Identifying Trading Ranges

An LR-R2 value near 0.0 indicates a lack of trend, usually appearing when a security is in a sideways trading range.

The chart below shows Blackrock (BLK) dropping from its high in early September and then flattening out by the end of the month. The strong downward trend resulted in LR-R2 values near 1.0 for several days, but they quickly dropped to near zero as price flattened out.&#x20;

<figure><img src="https://436553459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FERtrZrZOhufFzk6ZQO4B%2Fuploads%2FAdaV6xWD3PuYaeBhJ6al%2Flrr2flattrend.png?alt=media&amp;token=3ba40a22-fb9d-43e9-84a8-baedd74ee4f9" alt=""><figcaption><p>LR-R2 values near 0.0 indicate a lack of trend - typically a sideways trading range.</p></figcaption></figure>

### Identifying Weak Trends

The previous examples covered LR-R2 values at either extreme, but what do values in the middle of the range indicate? If the value is around 0.5, it means there's about a 50% chance the price action is based on a linear relationship and a 50% chance that price action is related to events such as interest rate changes, inflation fears, or general economic fundamentals. It's a tossup whether the LR-R2 value means an emerging or weakening trend, or just choppy price action.

The chart below shows Oracle (ORCL) with a sharp rise in late July and early August, followed by extremely messy price movement from August through October. The LR-R2 line moves around a lot, but struggles to rise above the midpoint of 0.5. A case could be made for a downtrend emerging after the high in early September, but it is certainly not a strong trend. These LR-R2 values are more likely attributable to choppy price action.

<figure><img src="https://436553459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FERtrZrZOhufFzk6ZQO4B%2Fuploads%2FRvnHsMaMc90WbE2nM95T%2Flrr2weaktrend.png?alt=media&amp;token=0f71b0ad-4ab4-4140-b930-2a320b84fc13" alt=""><figcaption><p>Mid-range LR-R2 values can indicate weak trends or choppy price action.</p></figcaption></figure>

## The Bottom Line

Linear Regression R2 is a straightforward indicator to quickly check whether or not a security is trending. A value closer to 1.0 indicates a strong trend, and a value closer to 0.0 indicates a lack of trend. The indicator does not show the direction of the trend - only the trend's existence, and to some extent, its strength. As with all indicators, it should be used in conjunction with other technical analysis tools.

## Charting with LR-R2

### Using with StockChartsACP

This indicator can be added from the Chart Settings panel for your StockChartsACP chart. The indicator can be positioned above, below, or behind the security's price plot.

<figure><img src="https://436553459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FERtrZrZOhufFzk6ZQO4B%2Fuploads%2FqCStA797t6hg1vCGKTuM%2Flrr2inacp.png?alt=media&amp;token=d7f2f9ff-0b0d-414a-8d90-ae450f5a1b1c" alt=""><figcaption></figcaption></figure>

[Click here for a live version of this chart.](https://schrts.co/gaXdIagY)

By default, the indicator looks back 14 periods for its calculations. This parameter can be adjusted to meet your technical analysis needs. A larger number of periods will result in a smoother indicator line.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://chartschool.stockcharts.com/table-of-contents/technical-indicators-and-overlays/technical-indicators/linear-regression-r2.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
