Adaptive Trend ChannelAdaptive Trend Channel is designed to find the most reliable short-term and long-term trend channels automatically, instead of forcing the user to work with one arbitrary lookback length. The script scans a broad range of candidate periods, builds a regression-based channel for each one, and then compares them through a multi-factor selection process. The goal is not just to find a channel that looks clean, but one that is statistically solid and structurally meaningful. To do that, the indicator favors channels with strong linearity, efficient trend behavior, sufficient directional strength, good price containment inside the bands, controlled width, and stable quality across nearby lengths. This helps avoid weak or accidental fits and gives priority to channels that are more robust in practice.
For best results, it is strongly recommended to use a logarithmic chart and to enable the option "Enable for logarithmic price scale" in the indicator settings. This is especially important on assets with large percentage moves over time, because the channel geometry then reflects percentage-based price movement more accurately.
Color is also important and very simple to read:
if a very robust channel is found, it is displayed in blue by default. This means the selected channel passed the eligibility filters and qualified as a strong structure. If no channel is robust enough, the script can still display the best available candidate, but it will appear in gray by default.
OVERVIEW
Adaptive Trend Channel helps identify the best short-term and long-term trend channels without manually testing many different lengths. Instead of relying on fixed settings, it adapts to the market structure by selecting the channels that best balance fit, strength, consistency, and usability.
The indicator can display:
- the best short-term channel
- the best long-term channel
- an optional midline
- an optional data table with channel diagnostics
HOW IT WORKS
For each tested lookback period, the script builds a regression-based trend channel and measures its quality.
Two selection modes are available:
1. Pearson r
This mode focuses mainly on linear fit quality.
2. Robust Composite
This mode uses a broader decision framework and combines several factors to favor channels that are not only well fitted, but also more reliable as usable trend structures.
In Robust Composite mode, the selection can include:
- Pearson correlation
- trend efficiency
- ADX trend strength
- price containment inside the channel
- channel width control
- local stability across neighboring tested lengths
A channel is considered eligible only if it passes the minimum filters defined by the user, such as:
- minimum absolute Pearson r
- minimum ADX
- minimum containment ratio
- maximum allowed channel width
If at least one eligible channel is found, the strongest one is selected and displayed in blue by default.
If none qualifies, the script still displays the best available fallback channel, but in gray by default.
WHY THIS APPROACH
A fixed-length channel can work well in one market condition and fail badly in another. This script addresses that problem by testing multiple candidate lengths and ranking them with a more complete selection logic.
The method is designed to reduce three common issues:
- choosing an arbitrary lookback period
- overvaluing channels that only look good visually
- accepting channels that fit price poorly or are too unstable
By combining fit quality, structure, strength, containment, and stability, the indicator aims to produce channels that are more trustworthy and easier to interpret.
HOW TO READ IT
- The short-term channel helps track the active market structure.
- The long-term channel helps frame the broader trend.
- Blue by default means a robust eligible channel was found.
- Gray by default means the displayed channel is the best available one, but it did not pass the eligibility filters.
- The position of price inside the channel helps show whether price is near the upper band, lower band, or midline.
FEATURES
- Automatic search for the best short-term and long-term channels
- Adaptive selection across multiple lookback lengths
- Robust eligibility filtering
- Blue default color for robust eligible channels
- Gray default color for fallback non-eligible channels
- Support for linear and logarithmic mode
- Optional midline display
- Optional table with channel metrics
- Two detection methods: Pearson r or Robust Composite
TABLE METRICS
Depending on your settings, the table can display:
- best length
- selection metric
- stability
- trend efficiency
- Pearson r
- ADX
- annualized channel return
- annualized channel price return
MAIN INPUTS
- Show Best Short-Term Channel
- Show Best Long-Term Channel
- Enable for logarithmic price scale
- Display Deviation Multiplier
- Best Channel Detection
- minimum eligibility filters for Pearson r, ADX, containment, and width
- optional table settings
NOTES
- For best interpretation, use logarithmic mode on a logarithmic chart.
- Blue by default means the channel passed the eligibility filters and was considered robust.
- Gray by default means the script is showing the best fallback channel, but it is not eligible.
- Annualized return metrics are intended for daily, weekly, and monthly timeframes.
Adaptive Trend Channel is built for traders who want a more objective, adaptive, and robust way to identify high-quality trend channels.
Chỉ báo Pine Script®











