PROTECTED SOURCE SCRIPT
Chan Theory - Chanlun|CCZT

# Chan Theory - Chanlun|CCZT
## Overview
This indicator implements Chan Theory (缠论) structural analysis framework using Pine Script v5. It automatically identifies fractals, pens, segments, and pivot zones from price movements, providing objective structure-based trading signals.
**Key Features:**
- Real-time fractal and pen recognition with 4 pen type options
- Multi-level segment analysis (sub-level and main-level)
- Dynamic pivot zone identification and visualization
- Type I/II/III trading signal detection
- Customizable display settings for all structural components
## How It Works
### 1. Candlestick Containment Processing
Eliminates noise by processing candlestick containment relationships:
- **Uptrend**: Takes higher highs and higher lows
- **Downtrend**: Takes lower highs and lower lows
### 2. Fractal Recognition
Identifies top/bottom fractals on processed candlesticks:
- **Top Fractal**: Middle candlestick high > both adjacent highs
- **Bottom Fractal**: Middle candlestick low < both adjacent lows
### 3. Pen Construction (4 Types Available)
Connects valid fractals to form pens:
- **Classic Pen (老笔)**: Requires 5+ processed K-lines per pen
- **Optimized Pen (新笔)**: 4+ processed K-lines with 5+ raw K-lines
- **4K Pen**: 4 raw K-lines with specific conditions
- **Strict Pen (严笔)**: 5+ K-lines with directional validation
### 4. Segment Partitioning (3 Modes)
Groups pens into higher-level segments:
- **Dynamic Correction**: Real-time adjustment with new data
- **Strict Mode**: Full compliance with classical definitions
- **Extension Mode**: Flexible trend continuation handling
### 5. Pivot Zone Recognition
Identifies consolidation zones at multiple levels:
- Sub-level pivot zones (pen-based)
- Main-level pivot zones (segment-based)
- Real-time pivot extension visualization
## Trading Signals
### Type I Signals (1buy/1sell)
Trend reversal signals based on momentum divergence within segments. Requires pivot zone formation or sufficient pen count.
### Type II Signals (2buy/2sell)
Pullback entry signals occurring after Type I, identified by sub-level fractal confirmations.
### Type III Signals (3buy/3sell)
Breakout confirmation signals when price breaks and holds beyond prior pivot zones.
### Quasi-Type II Signals (L2buy/L2sell)
Similar to Type II but with less strict conditions.
## Settings Guide
| Setting | Description |
|---------|-------------|
| **Pen Type** | Choose Classic/Optimized/4K/Strict based on volatility |
| **Segment Mode** | Select calculation method matching your strategy |
| **Show Pivot Zones** | Toggle sub-level/main-level pivots |
| **Show Running Pen** | Display currently forming unconfirmed pen |
| **Fast Pen Mode** | Allow pens without complete fractals |
## Display Options
- Pen lines with customizable colors and width
- Segment lines for different levels
- Pivot zone boxes with gradient colors
- Trading signals at fractal positions
## Upcoming Features (Coming Soon)
The following features are planned for future releases:
### Pen & Fractal Enhancements
- Right containment check (启用右包含检查)
- Pen endpoint mode: Strict highest/lowest vs Secondary high/low (笔端点模式)
- Pen extension correction in secondary mode (次高次低模式启用笔延伸修正)
- Single pen to segment (单笔成段)
- Segment formation conditions (成段条件)
- K-line count for segment (K线数量)
- Pen/Segment count for trend (笔/段数量)
- Trend line start filter (趋势线起点过滤)
- Local extremum filter (局部极值过滤)
- Lookback period (回溯周期)
- 3K interval filter (3K间隔过滤)
- Raw K-line fractal display (显示原始K线分型)
- Raw fractal for pen (原始分型用于笔)
- Single pen to segment ratio (单笔成段比例)
- Top/Bottom to pen ratio (顶底成笔)
### Segment Enhancements
- Super trend line display (显示大趋势线)
- Trend line extension (趋势线延伸)
- Super trend line extension (大趋势线延伸)
- Super trend segment colors (线段颜色-大趋势线)
- Single segment to trend (单段成趋势)
- Trend breakthrough (趋势突破)
- Feature sequence gap detection (启用特征序列缺口检测)
### Pivot Zone Enhancements
- Big-level pivot zone display (大级别中枢)
- Early draw big-level pivot (提前绘制大级别中枢)
- Big-level pivot colors (大级别中枢颜色)
### Trading Signal Enhancements
- Big-level trading signals (大级别买卖点)
- Type 2 chain detection (类2链式判断)
- Type 3 search range (类3搜索范围)
- Type 3 rapid reversal alert (3类买卖点急速反转警报)
### MACD Divergence (Complete Module)
- Sub-level divergence display (显示次级别背驰)
- Main-level divergence display (显示本级别背驰)
- Type 1 divergence detection method (1买卖点背驰判断方式)
- Type 1 pivot requirement (1买卖点中枢要求)
- Type 1 divergence detection toggle (1类买卖点启用背驰判断)
### Signal Filtering (Complete Module)
- Fractal validity filter (买卖点分型过滤)
- Basic fractal filter (买卖点分型基础过滤)
- Type 1 MACD divergence filter (1买卖macd背驰过滤)
- Type 2 signal filter (2买卖点过滤)
- False signal trap avoidance (防狼术)
- Expected signal display (显示预期买卖点)
- Alert differentiation (警报区分)
### Feature Sequence (Complete Module)
- Feature sequence display (显示特征序列)
- Up/Down segment colors for feature sequence
## Notes
- This script is for technical analysis reference only
- Does not constitute investment advice
- Users should make independent trading decisions
- Best used in conjunction with Chan Theory MACD Divergence indicator
---
# 概述
本指标基于缠论(Chan Theory)技术分析框架,使用Pine Script v5实现价格结构的自动识别。自动解析分型、笔、线段和中枢等核心组件,提供客观的结构化交易信号。
**核心功能:**
- 实时分型和笔识别,提供4种笔类型选择
- 多级别线段分析(次级别和本级别)
- 动态中枢识别与可视化
- 一、二、三类买卖点检测
- 所有结构组件可自定义显示设置
## 工作原理
### 1. K线包含处理
消除K线包含关系带来的噪音:
- **上涨趋势**:取高点高值、低点高值
- **下跌趋势**:取高点低值、低点低值
### 2. 分型识别
在处理后的K线上识别顶底分型:
- **顶分型**:中间K线高点 > 两侧高点
- **底分型**:中间K线低点 < 两侧低点
### 3. 笔的构建(4种类型)
连接有效分型形成笔结构:
- **老笔**:每笔至少5根处理后K线
- **新笔**:4根处理后K线 + 5根原始K线
- **4K笔**:4根原始K线满足特定条件
- **严笔**:5根K线 + 方向验证
### 4. 线段划分(3种模式)
将笔组合成更高级别的线段:
- **当下延伸后修正**:随新数据实时调整
- **严格模式**:完全符合经典定义
- **延伸模式**:灵活处理趋势延续
### 5. 中枢识别
识别多级别的盘整区域:
- 次级别中枢(基于笔)
- 本级别中枢(基于线段)
- 实时中枢延伸可视化
## 买卖点信号
### 一类买卖点 (1buy/1sell)
基于线段内动量背驰的趋势反转信号,需要中枢形成或足够笔数。
### 二类买卖点 (2buy/2sell)
一类之后的回调入场信号,通过次级别分型确认识别。
### 三类买卖点 (3buy/3sell)
价格突破并站稳中枢边界的突破确认信号。
### 类二买卖点 (L2buy/L2sell)
条件较宽松的类似二类信号。
## 设置说明
| 设置项 | 说明 |
|--------|------|
| **笔的类型** | 根据波动性选择老笔/新笔/4K/严笔 |
| **线段模式** | 选择符合策略的计算方式 |
| **显示中枢** | 切换次级别/本级别中枢显示 |
| **运行中的笔** | 显示当前形成中的未确认笔 |
| **急速成笔** | 允许无完整分型成笔 |
## 显示选项
- 笔线条,可自定义颜色和宽度
- 不同级别的线段线条
- 中枢区域带渐变色
- 买卖点信号显示在分型位置
## 即将推出的功能(敬请期待)
以下功能计划在后续版本中发布:
### 分型、笔增强功能
- 启用右包含检查
- 笔端点模式:严格最高最低点 / 允许次高次低点
- 次高次低模式启用笔延伸修正
- 单笔成段
- 成段条件(突破极值/数量条件/任一满足)
- K线数量要求
- 笔/段数量要求
- 趋势线起点过滤
- 局部极值过滤
- 回溯周期
- 3K间隔过滤
- 显示原始K线分型
- 原始分型用于笔
- 单笔成段比例
- 顶底成笔
### 线段增强功能
- 显示大趋势线
- 趋势线延伸
- 大趋势线延伸
- 线段颜色(大趋势线)
- 单段成趋势
- 趋势突破
- 启用特征序列缺口检测
### 中枢增强功能
- 是否显示大级别中枢
- 提前绘制大级别中枢
- 大级别中枢颜色设置
### 买卖点增强功能
- 大级别买卖点
- 启用类2链式判断
- 类3搜索范围
- 启用3类买卖点急速反转警报
### MACD背驰模块(完整模块)
- 显示次级别背驰
- 显示本级别背驰
- 1买卖点背驰判断方式
- 1买卖点中枢要求
- 1类买卖点启用背驰判断
### 买卖点过滤模块(完整模块)
- 买卖点分型过滤
- 买卖点分型基础过滤
- 1买卖macd背驰过滤
- 2买卖点过滤
- 防狼术
- 显示预期买卖点
- 警报区分
### 特征序列模块(完整模块)
- 显示特征序列
- 上涨/下跌线段特征序列颜色
## 声明
- 本脚本仅供技术分析参考
- 不构成投资建议
- 用户应自行做出交易决策
- 建议结合缠论macd背驰指标使用
## Overview
This indicator implements Chan Theory (缠论) structural analysis framework using Pine Script v5. It automatically identifies fractals, pens, segments, and pivot zones from price movements, providing objective structure-based trading signals.
**Key Features:**
- Real-time fractal and pen recognition with 4 pen type options
- Multi-level segment analysis (sub-level and main-level)
- Dynamic pivot zone identification and visualization
- Type I/II/III trading signal detection
- Customizable display settings for all structural components
## How It Works
### 1. Candlestick Containment Processing
Eliminates noise by processing candlestick containment relationships:
- **Uptrend**: Takes higher highs and higher lows
- **Downtrend**: Takes lower highs and lower lows
### 2. Fractal Recognition
Identifies top/bottom fractals on processed candlesticks:
- **Top Fractal**: Middle candlestick high > both adjacent highs
- **Bottom Fractal**: Middle candlestick low < both adjacent lows
### 3. Pen Construction (4 Types Available)
Connects valid fractals to form pens:
- **Classic Pen (老笔)**: Requires 5+ processed K-lines per pen
- **Optimized Pen (新笔)**: 4+ processed K-lines with 5+ raw K-lines
- **4K Pen**: 4 raw K-lines with specific conditions
- **Strict Pen (严笔)**: 5+ K-lines with directional validation
### 4. Segment Partitioning (3 Modes)
Groups pens into higher-level segments:
- **Dynamic Correction**: Real-time adjustment with new data
- **Strict Mode**: Full compliance with classical definitions
- **Extension Mode**: Flexible trend continuation handling
### 5. Pivot Zone Recognition
Identifies consolidation zones at multiple levels:
- Sub-level pivot zones (pen-based)
- Main-level pivot zones (segment-based)
- Real-time pivot extension visualization
## Trading Signals
### Type I Signals (1buy/1sell)
Trend reversal signals based on momentum divergence within segments. Requires pivot zone formation or sufficient pen count.
### Type II Signals (2buy/2sell)
Pullback entry signals occurring after Type I, identified by sub-level fractal confirmations.
### Type III Signals (3buy/3sell)
Breakout confirmation signals when price breaks and holds beyond prior pivot zones.
### Quasi-Type II Signals (L2buy/L2sell)
Similar to Type II but with less strict conditions.
## Settings Guide
| Setting | Description |
|---------|-------------|
| **Pen Type** | Choose Classic/Optimized/4K/Strict based on volatility |
| **Segment Mode** | Select calculation method matching your strategy |
| **Show Pivot Zones** | Toggle sub-level/main-level pivots |
| **Show Running Pen** | Display currently forming unconfirmed pen |
| **Fast Pen Mode** | Allow pens without complete fractals |
## Display Options
- Pen lines with customizable colors and width
- Segment lines for different levels
- Pivot zone boxes with gradient colors
- Trading signals at fractal positions
## Upcoming Features (Coming Soon)
The following features are planned for future releases:
### Pen & Fractal Enhancements
- Right containment check (启用右包含检查)
- Pen endpoint mode: Strict highest/lowest vs Secondary high/low (笔端点模式)
- Pen extension correction in secondary mode (次高次低模式启用笔延伸修正)
- Single pen to segment (单笔成段)
- Segment formation conditions (成段条件)
- K-line count for segment (K线数量)
- Pen/Segment count for trend (笔/段数量)
- Trend line start filter (趋势线起点过滤)
- Local extremum filter (局部极值过滤)
- Lookback period (回溯周期)
- 3K interval filter (3K间隔过滤)
- Raw K-line fractal display (显示原始K线分型)
- Raw fractal for pen (原始分型用于笔)
- Single pen to segment ratio (单笔成段比例)
- Top/Bottom to pen ratio (顶底成笔)
### Segment Enhancements
- Super trend line display (显示大趋势线)
- Trend line extension (趋势线延伸)
- Super trend line extension (大趋势线延伸)
- Super trend segment colors (线段颜色-大趋势线)
- Single segment to trend (单段成趋势)
- Trend breakthrough (趋势突破)
- Feature sequence gap detection (启用特征序列缺口检测)
### Pivot Zone Enhancements
- Big-level pivot zone display (大级别中枢)
- Early draw big-level pivot (提前绘制大级别中枢)
- Big-level pivot colors (大级别中枢颜色)
### Trading Signal Enhancements
- Big-level trading signals (大级别买卖点)
- Type 2 chain detection (类2链式判断)
- Type 3 search range (类3搜索范围)
- Type 3 rapid reversal alert (3类买卖点急速反转警报)
### MACD Divergence (Complete Module)
- Sub-level divergence display (显示次级别背驰)
- Main-level divergence display (显示本级别背驰)
- Type 1 divergence detection method (1买卖点背驰判断方式)
- Type 1 pivot requirement (1买卖点中枢要求)
- Type 1 divergence detection toggle (1类买卖点启用背驰判断)
### Signal Filtering (Complete Module)
- Fractal validity filter (买卖点分型过滤)
- Basic fractal filter (买卖点分型基础过滤)
- Type 1 MACD divergence filter (1买卖macd背驰过滤)
- Type 2 signal filter (2买卖点过滤)
- False signal trap avoidance (防狼术)
- Expected signal display (显示预期买卖点)
- Alert differentiation (警报区分)
### Feature Sequence (Complete Module)
- Feature sequence display (显示特征序列)
- Up/Down segment colors for feature sequence
## Notes
- This script is for technical analysis reference only
- Does not constitute investment advice
- Users should make independent trading decisions
- Best used in conjunction with Chan Theory MACD Divergence indicator
---
# 概述
本指标基于缠论(Chan Theory)技术分析框架,使用Pine Script v5实现价格结构的自动识别。自动解析分型、笔、线段和中枢等核心组件,提供客观的结构化交易信号。
**核心功能:**
- 实时分型和笔识别,提供4种笔类型选择
- 多级别线段分析(次级别和本级别)
- 动态中枢识别与可视化
- 一、二、三类买卖点检测
- 所有结构组件可自定义显示设置
## 工作原理
### 1. K线包含处理
消除K线包含关系带来的噪音:
- **上涨趋势**:取高点高值、低点高值
- **下跌趋势**:取高点低值、低点低值
### 2. 分型识别
在处理后的K线上识别顶底分型:
- **顶分型**:中间K线高点 > 两侧高点
- **底分型**:中间K线低点 < 两侧低点
### 3. 笔的构建(4种类型)
连接有效分型形成笔结构:
- **老笔**:每笔至少5根处理后K线
- **新笔**:4根处理后K线 + 5根原始K线
- **4K笔**:4根原始K线满足特定条件
- **严笔**:5根K线 + 方向验证
### 4. 线段划分(3种模式)
将笔组合成更高级别的线段:
- **当下延伸后修正**:随新数据实时调整
- **严格模式**:完全符合经典定义
- **延伸模式**:灵活处理趋势延续
### 5. 中枢识别
识别多级别的盘整区域:
- 次级别中枢(基于笔)
- 本级别中枢(基于线段)
- 实时中枢延伸可视化
## 买卖点信号
### 一类买卖点 (1buy/1sell)
基于线段内动量背驰的趋势反转信号,需要中枢形成或足够笔数。
### 二类买卖点 (2buy/2sell)
一类之后的回调入场信号,通过次级别分型确认识别。
### 三类买卖点 (3buy/3sell)
价格突破并站稳中枢边界的突破确认信号。
### 类二买卖点 (L2buy/L2sell)
条件较宽松的类似二类信号。
## 设置说明
| 设置项 | 说明 |
|--------|------|
| **笔的类型** | 根据波动性选择老笔/新笔/4K/严笔 |
| **线段模式** | 选择符合策略的计算方式 |
| **显示中枢** | 切换次级别/本级别中枢显示 |
| **运行中的笔** | 显示当前形成中的未确认笔 |
| **急速成笔** | 允许无完整分型成笔 |
## 显示选项
- 笔线条,可自定义颜色和宽度
- 不同级别的线段线条
- 中枢区域带渐变色
- 买卖点信号显示在分型位置
## 即将推出的功能(敬请期待)
以下功能计划在后续版本中发布:
### 分型、笔增强功能
- 启用右包含检查
- 笔端点模式:严格最高最低点 / 允许次高次低点
- 次高次低模式启用笔延伸修正
- 单笔成段
- 成段条件(突破极值/数量条件/任一满足)
- K线数量要求
- 笔/段数量要求
- 趋势线起点过滤
- 局部极值过滤
- 回溯周期
- 3K间隔过滤
- 显示原始K线分型
- 原始分型用于笔
- 单笔成段比例
- 顶底成笔
### 线段增强功能
- 显示大趋势线
- 趋势线延伸
- 大趋势线延伸
- 线段颜色(大趋势线)
- 单段成趋势
- 趋势突破
- 启用特征序列缺口检测
### 中枢增强功能
- 是否显示大级别中枢
- 提前绘制大级别中枢
- 大级别中枢颜色设置
### 买卖点增强功能
- 大级别买卖点
- 启用类2链式判断
- 类3搜索范围
- 启用3类买卖点急速反转警报
### MACD背驰模块(完整模块)
- 显示次级别背驰
- 显示本级别背驰
- 1买卖点背驰判断方式
- 1买卖点中枢要求
- 1类买卖点启用背驰判断
### 买卖点过滤模块(完整模块)
- 买卖点分型过滤
- 买卖点分型基础过滤
- 1买卖macd背驰过滤
- 2买卖点过滤
- 防狼术
- 显示预期买卖点
- 警报区分
### 特征序列模块(完整模块)
- 显示特征序列
- 上涨/下跌线段特征序列颜色
## 声明
- 本脚本仅供技术分析参考
- 不构成投资建议
- 用户应自行做出交易决策
- 建议结合缠论macd背驰指标使用
Script protetto
Questo script è pubblicato come codice protetto. Tuttavia, è possibile utilizzarle liberamente e senza alcuna limitazione – ulteriori informazioni qui.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Script protetto
Questo script è pubblicato come codice protetto. Tuttavia, è possibile utilizzarle liberamente e senza alcuna limitazione – ulteriori informazioni qui.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.