OPEN-SOURCE SCRIPT

Support and Resistance Polynomial Regressions | Flux Charts

Updated
Overview

This script is a dynamic form of support and resistance. Support and resistance plots areas where price commonly reverses its direction or “pivots”. A resistance line for instance is typically found by locating a price point where multiple high pivots occur. A high pivot is where a price increases for a number of bars then decreases for a number of bars creating a local maximum. This script takes the high pivots points but rather than using a horizontal line a polynomial regressed line is used.

It is common to see consecutive higher highs or lower lows or a mixed pattern of both so a classical support or resistance line can be insufficient. This script lets users find a polynomial of best fit for high pivots and low pivots creating a resistance and support line respectively.

Here are the same two sets of high and low pivots the first using linear regressed support and resistance lines the second using quadratic.
snapshot
snapshot

Here are the predicted results:
snapshot
snapshot

The Quadratic regression gives a much more accurate prediction of future pivot areas and the increase in variance of the data.

Quick Start

Add the script to the chart. Then select a left point and right point on the chart. This will be the data the script uses to calculate a best fit resistance line. Then select another left and right point that will be for the support line.

Now you can confirm your basic settings like the type of regression: Linear Regression, Quadratic Regression, Cubic Regression or Custom Regression.

After confirming the lines will be plotted on the graph.


Custom Polynomial Regression Setting
Polynomials follow the form:
snapshot

The degree of a polynomial is the highest exponent in the equation. For example the polynomial ax^2 + bx + c has a degree of 2.

Here are the default polynomial options and their equivalent custom polynomial entry:

snapshot

This allows us to create regressions with a custom number of inflection points. An inflection point is a point where the graph changes from concave up to concave down or vice versa. The maximum number of inflection points a polynomial can have is the degree - 2. Having multiple inflection points in our regression allows for having a closer fit minimizing error.

It should be noted that having a closer fit is not inherently better; this can cause overfitting. Overfitting is when a model is too closely fit to the training data and not generalizable to the population data.
Release Notes
Added a rolling calculation setting for support and resistance lines.
This allows users to have the data period update relative to the live bar. If a new data point enters the data period or the data period moves past an old data point the regression will recalculate.
Bands and Channelsforecastingregressions

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 Flux Charts indicators: fluxcharts.com/?via=tv

Free trade signals for stocks, crypto, forex, and futures: discord.gg/fluxcharts
Also on:

Disclaimer