PROTECTED SOURCE SCRIPT

Adaptive Trend Channel 自适应趋势通道

134
Overview

Adaptive Trend Channel (Logarithmic)
This indicator automatically selects the most trend-consistent period using logarithmic regression and Pearson’s R correlation. It then plots the midline (trend regression) along with upper/lower channel bands based on standard deviation.

Automatic period selection: Chooses the length with the strongest correlation between price and projected trend.

Adaptive channel width: Calculated using unbiased standard deviation of regression residuals.

Information panel: Displays selected period, trend strength (or Pearson’s R), and annualized return (CAGR, available only on daily/weekly).

Dual modes: Short-term (20–200 bars) and long-term (300–1200 bars). Load the indicator twice if you want to visualize both at the same time.

Key Features

Automatic trend detection based on maximum Pearson’s R.

Logarithmic regression midline with symmetric deviation channels.

Customizable visuals: colors, line styles, transparency, channel extension.

Information panel: bilingual-friendly, showing auto-selected period, trend strength, Pearson’s R, and CAGR (when applicable).

Inputs

Source: default close.

Use Long-Term Channel: toggles between short-term (20–200) and long-term (300–1200).

Deviation Multiplier: adjusts channel width (default = 2.0).

Channel Appearance: line style, extension type (right, both, none, left), transparency.

Midline Appearance: color, style, width, transparency.

Information Panel: show/hide components, position, text size.

CAGR Calculation: available on daily (D) and weekly (W) timeframes.

How to Use

Add the script to your chart.

Choose a mode:

Short-term (20–200 bars): disable "Use Long-Term Channel".

Long-term (300–1200 bars): enable "Use Long-Term Channel".

View both short & long: load the indicator twice, once in each mode, and assign different colors for clarity.

Customize line styles, colors, and extension behavior.

Check the panel: see the automatically selected period, correlation-based trend strength, and CAGR (on D/W).

Practical Tips

Data length matters: If channels don’t show or the panel reads "N/A", scroll back to load more history or reduce maximum long-term length.

Trend confidence:

Pearson’s R closer to 1 = stronger correlation.

Enable "Show Pearson’s R" to view exact values.

Channel width:

Increase multiplier for wider, more tolerant channels.

Decrease for tighter, more precise bands.

Extension: choose right/both/none/left depending on how you want channels projected into the future.

Important Notes

Log-based calculation: works only with strictly positive prices.

Timeframe requirement: CAGR is meaningful only on D/W.

Long-term mode: requires sufficient history (up to 1200 bars).

Market differences:

Crypto annualization = 365 days.

Stocks/other = 252 trading days.

Weekly = 52 weeks.

Non-predictive: Channels are statistical regressions of past data, not guaranteed forecasts.
简介 | Overview

自适应趋势通道(对数) / Adaptive Trend Finder (Log)

基于对数价格回归与皮尔逊相关系数(Pearson’s R)自动选择最“顺趋势”的周期,在该周期上绘制中线 + 上下通道。

通道宽度由回归残差的无偏标准差决定,配合“偏差倍数”构建带状区间。

提供趋势强度/相关系数与(仅日线/周线)**年化收益率(CAGR)**信息面板。

可一键切换短期/长期模式;如需同时显示长+短两套通道,请在图表上加载两次本指标。

版权 | License:© Julien Eche,GPL-3.0

主要功能 | Key Features

自动择期:在一组预设长度中寻找 Pearson’s R 最高的周期。

对数回归通道:中线 = 回归拟合线;上下轨 = 按标准差×倍数偏移。

可视化信息面板:显示自动周期、趋势强度/相关系数、年化收益(D/W)。

风格可调:通道颜色、线型、延长方式、透明度均可配置。

参数说明 | Inputs

价格源 / Source:默认 close。

使用长期通道 / Use Long-Term Channel:

关=短期(20–200);开=长期(300–1200)。

If both short & long are needed, add the indicator twice (one short, one long).

偏差倍数 / Deviation Multiplier:控制通道宽度(默认 2.0)。

通道颜色/线型/延长/透明度:外观设置。

中线颜色/线型/宽度/透明度:中线外观设置。

面板设置 / Table:显示内容开关、位置与字号。

年化收益(CAGR):仅在 日线/周线显示;加密按 365天,股票按 252交易日年化。

如何使用 | How to Use

添加指标:将脚本粘贴到 Pine 编辑器并添加到图表。

选择周期模式:

短期:关闭“使用长期通道”;

长期:打开“使用长期通道”。

同时显示长+短:在图表上再次添加同一指标,一个设短期,一个设长期。

调整外观:根据需要调整通道颜色、线型、延长方式、透明度等。

读取面板:查看“自动选择周期”“趋势强度/皮尔逊R”“趋势年化收益”。

实战提示 | Pro Tips

历史数据不足:若面板显示 N/A 或不出线,向左多滚动加载更多历史;或降低“长期”上限(如≤800)。

强弱判断:

趋势强度基于 Pearson’s R;接近 1 表示走势与回归更一致。

若勾选“显示 Pearson’s R”,面板会直接显示 R 值。

通道延长:用“向右延长/两端延长/不延长/向左延长”控制线段延伸。

通道宽度:扩大“偏差倍数”可容纳更多波动,缩小则更贴近价格。

性能:计算集中在最后一根K线(barstate.islast),在长周期与长历史下也较为顺畅。

重要注意事项 | Important Notes

仅对数价格:脚本使用 log(price),需保证价格为正值(大多品种满足)。

时间框支持:CAGR 仅在 D/W 有意义;其他周期面板将显示“不可用”。

长周期可见性:长期模式(最高至 1200 根)需要足够历史,否则无法选期。

不同市场年化基数:加密按 365 天,股票等按 252 交易日,周线按 52 周。

信号非保证:通道与统计为历史拟合结果,不构成投资建议。

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

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