Editors' picksOPEN-SOURCE SCRIPT

Periodic Linear Regressions [LuxAlgo]

The Periodic Linear Regressions (PLR) indicator calculates linear regressions periodically (similar to the VWAP indicator) based on a user-set period (anchor).

This allows for estimating underlying trends in the price, as well as providing potential supports/resistances.

🔶 USAGE

snapshot

The Periodic Linear Regressions indicator calculates a linear regression over a user-selected interval determined from the selected "Anchor Period".

The PLR can be visualized as a regular linear regression (Static), with a fit readjusting for new data points until the end of the selected period, or as a moving average (Rolling), with new values obtained from the last point of a linear regression fitted over the calculation interval. While the static method line is prone to repainting, it has value since it can further emphasize the linearity of an underlying trend, as well as suggest future trend directions by extrapolating the fit.

snapshot

Extremities are included in the indicator, these are obtained from the root mean squared error (RMSE) between the price and calculated linear regression. The Multiple setting allows the users to control how far each extremity is from the other.

Periodic Linear Regressions can be helpful in finding support/resistance areas or even opportunities when ranging in a channel.

snapshot

snapshot

The anchor - where a new period starts - can be shown (in this case in the top right corner).

snapshot

The shown bands can be visualized by enabling Show Extremities in settings (Rolling or Static method).

snapshot

The script includes a background gradient color option for the bands, which only applies when using the Rolling method.

The indicator colors can be suggestive of the detected trend and are determined as follows:

  • Method Rolling: a gradient color between red and green indicates the trend; more green if the output is rising, suggesting an uptrend, and more red if it is decreasing, suggesting a downtrend.
  • Method Static: green if the slope of the line is positive, suggesting an uptrend, red if negative, suggesting a downtrend.


🔶 DETAILS

🔹 Anchor Type

When the Anchor Type is set to Periodic, the indicator will be reset when the "Anchor Period" changes, after which calculations will start again.

An anchored rolling line set at First Bar won't reset at a new session; it will continue calculating the linear regression from the first bar to the last; in other words, every bar is included in the calculation. This can be useful to detect potential long-term tops/bottoms.

snapshot

Note that a linear regression needs at least two values for its calculation, which explains why you won't see a static line at the first bar of the session. The rolling linear regression will only show from the 3rd bar of the session since it also needs a previous value.

🔹 Rolling/Static

When Anchor Type is set at Periodic, a linear regression is calculated between the first bar of the chosen session and the current bar, aiming to find the line that best fits the dataset.

snapshot

The example above shows the lines drawn during the session. The offered script, though, shows the last calculated point connected to the previous point when the Rolling method is chosen, while the Static method shows the latest line.

snapshot

Note that linear regression needs at least two values, which explains why you won't see a static line at the first bar of the session. The rolling line will only show from the 3rd bar of the session since it also needs a previous value.

🔶 SETTINGS

  • Method: Indicator method used, with options: "Static" (straight line) / "Rolling" (rolling linear regression).
  • Anchor Type: "Periodic / First Bar" (the latter works only when "Method" is set to "Rolling").
  • Anchor Period: Only applicable when "Anchor Type" is set at "Periodic".
  • Source: open, high, low, close, ...
  • Multiple: Alters the width of the bands when "Show Extremities" is enabled.
  • Show Extremities: Display one upper and one lower extremity.


🔹 Color Settings

  • Mono Color: color when "Bicolor" is disabled
  • Bicolor: Toggle on/off + Colors
  • Gradient: Background color when "Show extremities" is enabled + level of gradient


🔹 Dashboard

  • Show Dashboard
  • Location of dashboard
  • Text size
bandslinear-regressionLinear RegressionluxalgoParallel ChannelperiodicregressionsupportSupport and ResistancesupportandresistancezonesTrend Analysis

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?


Get access to our exclusive tools: luxalgo.com

Join our 150k+ community: discord.gg/lux

All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
Also on:

Disclaimer