OPEN-SOURCE SCRIPT

Regression Channel Auto

484
Regression Channel Auto is a visual trend-structure tool based on least-squares linear regression.

The script draws a regression channel on the chart using either a fixed lookback length or an automatically selected best-fit length. In Auto mode, the script evaluates the available lookback lengths between the user-defined minimum and maximum settings, then selects the window with the highest absolute Pearson correlation. This helps identify the recent price segment that is most closely aligned with a straight-line regression structure.

What the script shows

- A center regression line
- Inner regression bands
- Outer regression bands
- Optional channel fill
- Direction-based coloring for rising, falling, or flat channel slopes
- Optional visual extension to the right
- Optional outside-channel break markers
- Optional alerts for closes outside the outer channel

How it works

The script calculates a least-squares regression line over the selected lookback window. It then measures the residual deviation around that regression line and plots inner and outer bands at user-defined deviation distances.

The channel color changes according to the slope of the regression line:

- Rising channel: positive slope above the flat threshold
- Falling channel: negative slope below the flat threshold
- Flat channel: slope inside the selected flat threshold

Auto Length mode

In Auto mode, the script scans the lookback range selected by the user and chooses the length with the strongest absolute Pearson correlation. This means the selected channel is the one whose recent price structure is most linear within the evaluated range.

A high correlation value describes how closely price followed a linear path during the selected window. It does not predict future price movement.

Fixed Length mode

Fixed mode uses one user-defined lookback length. This is useful when the user wants a stable channel length instead of an automatically changing one.

Main settings

Channel:
- Length mode
- Fixed length
- Auto minimum length
- Auto maximum length
- Source
- Flat threshold

Bands:
- Inner band deviation
- Outer band deviation
- Show inner bands
- Show channel fill

Display:
- Extend channel right
- Show info label
- Show current outer break marker

Lines:
- Center line width
- Inner band width
- Outer band width
- Center line style
- Inner band style
- Outer band style

Colors:
- Rising channel color
- Falling channel color
- Flat channel color
- Inner band transparency
- Channel fill transparency

Alerts

The script includes optional alert conditions for:

- Close above the upper outer regression channel
- Close below the lower outer regression channel

These alerts describe price moving outside the selected regression channel. They are not buy or sell signals.

How to use

Use this indicator to review whether price is moving inside a structured linear channel, near the upper or lower side of the channel, or outside the outer deviation bands.

The tool can be useful for visual trend review, mean-deviation context, and identifying when price has moved outside its recent regression structure.

Important note on refitting

This script is recalculated as new bars develop. In Auto mode, the selected lookback length can also change when new price data changes which window has the highest absolute Pearson correlation.

For this reason, the channel should be understood as a dynamic descriptive tool. It is not a fixed historical signal and it should not be interpreted as a prediction model.

Limitations

- The channel is based on recent price structure only.
- A high Pearson correlation measures linearity, not future performance.
- A close outside the channel does not automatically mean continuation or reversal.
- Outer-band contact is not a standalone trading signal.
- The optional right extension is a visual reference only and is not a forecast.

This indicator is intended for chart analysis, educational use, and visual review of regression-channel structure.

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน