INVITE-ONLY SCRIPT

Chan Theory - Chanlun Pro | CJZT

73
# Chan Theory - Chanlun Pro | CJZT

## Overview
This is the professional version of Chan Theory (缠论) structural analysis indicator, built with Pine Script v6. It provides comprehensive multi-level structure recognition, advanced trading signals, MACD divergence analysis, and additional professional tools including Pivot Points support/resistance levels, liquidity-weighted moving averages, and customizable alert systems.

**Why This Indicator?**
Real market movements rarely follow textbook patterns. This indicator addresses this reality with:
- **Single Pen to Segment**: When a powerful pen breaks the previous level's extreme or meets K-line count requirements (configurable 5-30 K-lines), it can directly become a segment
- **9-Pen Segment to Trend**: A segment containing 9+ pens can upgrade to trend line level
- **Flexible Level Upgrade**: Multiple conditions (extremum breakthrough, count requirements, or either) allow the structure to adapt to actual market behavior
- **4K/5K Pen Types**: Designed to better fit sub-cycle movements with shorter K-line requirements
- **Top/Bottom to Pen**: When top/bottom fractal strength is significant, allows pen formation based on amplitude ratio
- **Professional Tools**: Includes Pivot Points, liquidity-weighted MAs, and advanced filtering systems

**Key Features:**
- 5 pen types: Classic, Optimized, 4K, 5K, Strict
- 3 segment modes: Dynamic Correction, Strict, Extension
- 3-level structure: Pens → Segments → Trend Lines
- Complete Type I/II/III trading signals
- MACD divergence analysis
- Pivot Points support/resistance (Traditional, Fibonacci, Camarilla)
- Liquidity-weighted moving averages
- Advanced signal filtering system
- Custom alert configurations

## What Makes This Indicator Original

This indicator is an original implementation of Chan Theory with several unique innovations:

**1. Flexible Level Upgrade System**
Unlike traditional Chan Theory indicators that strictly require 3 pens to form a segment, this indicator introduces practical upgrade conditions. A powerful pen can directly become a segment when it breaks the previous level's extreme OR meets K-line count requirements (configurable 5-30 K-lines).

**2. Five Distinct Pen Construction Types**
Provides multiple pen detection methods (Classic/Optimized/4K/5K/Strict) to fit different market conditions and timeframes, allowing traders to choose the most appropriate method for their trading style.

**3. Integrated Professional Tools**
Combines Chan Theory analysis with professional trading tools:
- **Pivot Points**: Classic support/resistance levels using public domain algorithms (Traditional, Fibonacci, Camarilla)
- **Liquidity-Weighted MAs**: Advanced moving averages based on volume and price movement
- **Custom Alert System**: Configure specific combinations of buy/sell signals for personalized alerts

**4. Three-Level Hierarchical Structure**
Complete implementation of Pens → Segments → Trend Lines with independent controls for each level, including separate extension modes and signal generation.

**5. Comprehensive Signal Filtering**
Multiple filter options including fractal validation, MACD divergence, zero-axis filters, and liquidity confirmation to improve signal quality.

## Core Functions

### 1. Candlestick Containment Processing
Advanced containment processing with configurable options:
- **Left Containment**: Standard processing
- **Right Containment Check**: Optional additional validation
- Recursive processing ensures complete elimination

### 2. Pen Construction (5 Types)
| Type | Description |
|------|-------------|
| **Classic (老笔)** | 5+ processed K-lines per pen |
| **Optimized (新笔)** | 4+ processed + 5+ raw K-lines |
| **4K** | 4 raw K-lines with extremum validation |
| **5K** | 5 raw K-lines standard |
| **Strict (严笔)** | 5+ K-lines with directional validation |

### 3. Single Pen to Segment
Advanced level upgrade conditions:
- **Extremum Breakthrough**: Based on breaking previous level extremes
- **K-line Count**: Based on K-line count (5-30 configurable)
- **Either Satisfied**: Either condition can trigger upgrade

### 4. Segment Modes
| Mode | Description |
|------|-------------|
| **Strict Mode** | No extension, segments only form when fully confirmed |
| **Extension Mode** | Allows segment extension for current market tracking |
| **Dynamic Correction** | Extends first, then corrects based on new information |

### 5. Trading Signals
Complete Type I/II/III signal system:
- **Type I (1buy/1sell)**: Trend reversal based on divergence
- **Type II (2buy/2sell)**: Pullback entries at pivot zones
- **Type III (3buy/3sell)**: Breakout confirmations

### 6. Pivot Points Support/Resistance
Classic pivot point calculations for identifying key price levels:
- **Traditional**: Standard pivot point formula
- **Fibonacci**: Fibonacci-based levels (38.2%, 61.8%)
- **Camarilla**: Intraday support/resistance levels
- Configurable timeframes (Daily, Weekly, Monthly, etc.)

### 7. Liquidity-Weighted Moving Averages
Advanced moving averages that consider volume and price movement:
- Fast and slow MA with customizable periods
- Outlier detection for identifying unusual liquidity events
- Visual fill between MAs for trend identification

### 8. Signal Filtering
Multiple filter options to improve signal quality:
- Fractal validation filter
- MACD divergence filter for Type I signals
- MACD zero-axis filter for Type II signals
- Liquidity confirmation filter
- Expected signal system (early warning)

## How to Use

### Initial Setup
1. Add indicator to chart
2. Select pen type based on your timeframe:
- Intraday (1m-15m): Use 4K or 5K for faster response
- Swing (1H-4H): Use Classic or Optimized
- Position (Daily+): Use Strict for reliability

3. Configure level upgrade:
- Conservative: "Extremum Breakthrough" only
- Balanced: "Either Satisfied" (recommended)
- Aggressive: "K-line Count" only

### Professional Tools Setup
**Pivot Points:**
- Enable "显示 支撑阻力" to show pivot levels
- Choose pivot type (Traditional recommended for beginners)
- Select timeframe (Auto adapts to chart timeframe)

**Liquidity MAs:**
- Enable "显示流动性加权均线"
- Adjust fast/slow periods based on trading style
- Use for trend confirmation and liquidity analysis

### Trading with Signals
1. **Type I Signals**: Enter on trend reversal after divergence confirmation
2. **Type II Signals**: Enter on pullbacks within established trends
3. **Type III Signals**: Enter on breakouts from pivot zones
4. **Pivot Levels**: Use as additional confirmation for entries/exits

### Best Practices
- Use higher timeframe structure for trend direction
- Enter on lower timeframe signals aligned with higher timeframe trend
- Combine pivot levels with Chan Theory signals for confluence
- Set custom alerts for your preferred signal combinations

## Settings Reference

### Display Settings
| Setting | Description |
|---------|-------------|
| Show All Fractals | Display all top/bottom patterns |
| Running Pen | Show forming (unconfirmed) pen |
| K-line Merge | Visualize containment processing |
| Fast Pen Mode | Allow pens without complete fractals |

### Pen Settings
| Setting | Description |
|---------|-------------|
| Pen Type | Choose from 5 construction methods |
| Endpoint Mode | Strict vs flexible secondary extremes |
| Fractal Overlap | Allow overlapping fractals |
| Single Pen to Segment | Enable level upgrade features |
| Upgrade Condition | Extremum/Count/Either |
| K-line Count | 5-30 (for count condition) |

### Segment Settings
| Setting | Description |
|---------|-------------|
| Segment Mode | Dynamic Correction/Strict/Extension |
| Segment to Trend | Enable 9-pen segment to trend upgrade |
| Correction Ratio | 38.2%/50%/61.8%/78.6% Fibonacci ratios |

### Pivot Points Settings
| Setting | Description |
|---------|-------------|
| Pivot Type | Traditional/Fibonacci/Camarilla |
| Timeframe | Auto/Daily/Weekly/Monthly |
| Show Labels | Display level labels |
| Show Prices | Display price values |

### Liquidity MA Settings
| Setting | Description |
|---------|-------------|
| Fast MA Length | Default 50 periods |
| Slow MA Length | Default 100 periods |
| Outlier Threshold | Sensitivity for unusual liquidity |

### Signal Filtering
| Setting | Description |
|---------|-------------|
| Fractal Filter | Require post-fractal price confirmation |
| MACD Divergence Filter | Type I signals must show divergence |
| Zero-Axis Filter | Type II signals must align with MACD |
| Liquidity Filter | Signals must confirm with liquidity MAs |
| Show Expected Signals | Display anticipated signals |

## Disclaimer

- This script is for technical analysis reference only
- Does not constitute investment advice or trading recommendations
- Past performance does not guarantee future results
- Users should make independent trading decisions and manage their own risk
- Recommended for educational purposes and as a supplementary analysis tool

## Code Attribution

This indicator uses TradingView's built-in functions and public domain algorithms:
- **Moving Averages (MA/EMA)**: Uses TradingView's built-in `ta.sma()` and `ta.ema()` functions for the customizable moving average system
- **MACD**: Standard MACD calculation using TradingView's built-in `ta.macd()` function
- **Pivot Points**: Traditional, Fibonacci, and Camarilla pivot point calculations are classic technical analysis methods widely available across all trading platforms

All Chan Theory structural analysis logic (pen construction, segment formation, pivot zone detection, and trading signal generation) is original implementation.

---

# 概述(中文)
本指标是缠论(Chan Theory)结构分析的专业版本,提供完整的多级别结构识别、高级交易信号、MACD背驰分析,以及专业工具包括支撑阻力位、流动性加权均线和自定义警报系统。

## 核心创新

**1. 灵活的级别升级系统**
单笔成段:笔可直接升级为线段(可配置5-30根K线)

**2. 五种笔类型**
适应不同市场环境:老笔、新笔、4K、5K、严笔

**3. 专业工具集成**
- 支撑阻力位(Pivot Points)
- 流动性加权均线
- 自定义警报系统

**4. 三级结构系统**
完整的层级分析:笔 → 线段 → 趋势线

**5. 完整的买卖点系统**
一二三类买卖点,支持预期信号和确认信号

## 使用方法

1. 根据周期选择笔类型
2. 配置级别升级条件
3. 启用专业工具(支撑阻力、流动性均线)
4. 观察结构形成和买卖点信号
5. 结合支撑阻力位确认入场

## 代码归属说明

本指标使用了公共领域算法:
- **支撑阻力位**:Traditional、Fibonacci、Camarilla 枢轴点计算是经典技术分析方法
- **MACD**:使用 TradingView 内置 `ta.macd()` 函数

所有缠论结构分析逻辑均为原创实现。

## 免责声明

本指标仅供技术分析参考,不构成投资建议。用户应自行做出交易决策并管理风险。

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.