> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.ninjatrader.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.ninjatrader.com/_mcp/server.

# Linear Regression

## Description

The Linear Regression Indicator plots the trend of a security's price over time. That trend is determined by calculating a Linear Regression Trendline using the least squares method. This ensures the minimum distance between the data points and a Linear Regression Trendline.

## Syntax

`LinReg(int period)`

`LinReg(ISeries\<double\> input, int period)`

**Returns default value**

`LinReg(int period)[int barsAgo]`

`LinReg(ISeries\<double\> input, int period)[int barsAgo]`

## Return Value

**double;** Accessing this method via an index value **\[int barsAgo]** returns the indicator value of the referenced bar.

## Parameters

| Parameter | Description                                                                                     |
| --------- | ----------------------------------------------------------------------------------------------- |
| input     | Indicator source data ([Series\<T>](/developer/desktop-sdk/references/common/iseriest/seriest)) |
| period    | Number of bars used in the calculation                                                          |

## Examples

```csharp

// Prints the current value of a 20 period LinReg using default price type
double value = LinReg(20)[0];
Print("The current LinReg value is " + value.ToString());

// Prints the current value of a 20 period LinReg using high price type
double value = LinReg(High, 20)[0];
Print("The current LinReg value is " + value.ToString());
```

## Source Code

You can view this indicator method source code by selecting the menu New > NinjaScript Editor > Indicators within the NinjaTrader Control Center window.