OPEN-SOURCE SCRIPT

chanlun缠论 - 笔与中枢

248
Overview
The Chanlun (缠论) Strokes & Central Zones indicator is an advanced technical analysis tool based on Chinese Chan Theory (Chanlun Theory). It automatically identifies market structure through "strokes" (笔) and "central hubs" (中枢), providing traders with a systematic framework for understanding price movements, trend structure, and potential reversal zones.
Theoretical Foundation
Chan Theory is a sophisticated price action methodology that breaks down market movements into hierarchical structures:

Local Extremes: Swing highs and lows identified through lookback periods
Strokes (笔): Valid price movements between opposite extremes that meet specific criteria
Central Hubs (中枢): Consolidation zones formed by overlapping strokes, representing key support/resistance areas

Key Components
1. Local Extreme Detection

Identifies swing highs and lows using a configurable lookback period (default: 5 bars)
Only considers extremes within the specified calculation range
Forms the foundation for stroke construction

2. Stroke (笔) Identification
The indicator applies a multi-stage filtering process to identify valid strokes:
Stage 1 - Extreme Consolidation:

Merges consecutive extremes of the same type (high or low)
Keeps only the most extreme value (highest high or lowest low)

Stage 2 - Stroke Validation:

Ensures minimum bar gap between strokes (default: 4 bars)
Alternative validation: 2+ bars with >1% price change
Eliminates noise and insignificant price movements

Color Coding:

White Lines: Regular up/down strokes
Yellow Lines: Strokes that form part of a central hub
Customizable width and colors for different stroke types

3. Central Hub (中枢) Formation
A central hub forms when at least 3 consecutive strokes have overlapping price ranges:
Formation Rules:
Stroke 1: [Low1, High1]
Stroke 2: [Low2, High2]
Stroke 3: [Low3, High3]

Hub Upper = MIN(High1, High2, High3)
Hub Lower = MAX(Low1, Low2, Low3)

Valid if: Hub Upper > Hub Lower
Hub Extension:

Subsequent strokes that overlap with the hub extend it
Hub ends when a stroke no longer overlaps
Creates rectangular zones on the chart

Visual Representation:

Green rectangular boxes: Mark the time and price range of each central hub
Dashed extension lines: Show the latest hub boundaries extending to the right
Price labels on axis: Display exact hub upper and lower boundary values

4. Extreme Point Markers (Optional)

Red markers for tops (▼)
Green markers for bottoms (▲)
Marks every validated stroke extreme point
Useful for detailed structure analysis

5. Information Table (Optional)
Displays real-time statistics:

Symbol name
Current timeframe
Lookback period setting
Minimum gap setting
Total stroke count

Parameter Settings
Performance Settings

Max Bars to Calculate (3600): Limits historical calculation to improve performance
Local Extreme Lookback Period (5): Bars used to identify swing highs/lows
Min Gap Bars (4): Minimum bars required between valid strokes

Display Settings

Show Strokes: Toggle stroke line visibility
Show Central Hub: Toggle hub box visibility
Show Hub Extension Lines: Toggle dashed boundary lines
Show Extreme Point Marks: Toggle top/bottom markers
Show Info Table: Toggle statistics table

Color Settings
Full customization of:

Up/down stroke colors and widths
Hub stroke colors and widths
Hub border and background colors
Extension line colors

Trading Applications
Trend Structure Analysis

Uptrend: Series of higher highs and higher lows connected by strokes
Downtrend: Series of lower highs and lower lows connected by strokes
Consolidation: Formation of central hubs indicating range-bound movement

Support and Resistance Identification

Central Hub Zones: Act as strong support/resistance areas
Hub Upper Boundary: Resistance level in consolidation, support after breakout
Hub Lower Boundary: Support level in consolidation, resistance after breakdown
Price tends to react at these levels due to market structure memory

Breakout Trading

Bullish Breakout: Price closes above hub upper boundary

Previous resistance becomes support
Entry on retest of upper boundary
Stop loss below hub zone


Bearish Breakdown: Price closes below hub lower boundary

Previous support becomes resistance
Entry on retest of lower boundary
Stop loss above hub zone



Reversal Detection

Hub Formation After Trend: Signals potential trend exhaustion
Multiple Hub Levels: Create probability zones for reversals
Stroke Count: Excessive strokes within hub suggest weakening momentum

Position Management

Use hub boundaries for stop loss placement
Scale out positions at hub edges
Re-enter on retests of broken hub levels

Interpretation Guide
Strong Trending Market

Long, clear strokes with minimal overlap
Few or no central hubs forming
Strokes consistently in same direction
Wide spacing between extremes

Consolidating Market

Multiple central hubs forming
Short, overlapping strokes
Yellow hub strokes dominate the chart
Narrow price range

Trend Transition

Hub formation after extended trend
Stroke direction changes frequently
Hub boundaries being tested repeatedly
Potential reversal zone

Advanced Usage Techniques
Multi-Timeframe Analysis

Higher Timeframe: Identify major hub zones for overall market structure
Lower Timeframe: Find precise entry points within larger structure
Alignment: Trade when lower timeframe strokes align with higher timeframe hub breaks

Hub Quality Assessment

Wide Hubs: Strong consolidation, higher probability support/resistance
Narrow Hubs: Weak consolidation, may break easily
Extended Hubs: More strokes = stronger zone
Isolated Hubs: Single hub = potential pivot point

Stroke Analysis

Stroke Length: Longer strokes = stronger momentum
Stroke Speed: Fewer bars per stroke = explosive moves
Stroke Clustering: Many short strokes = indecision

Best Practices

Parameter Optimization

Adjust lookback period based on timeframe and volatility
Lower periods (3-4): More strokes, more noise, faster signals
Higher periods (7-10): Fewer strokes, cleaner structure, slower signals


Confirmation Strategy

Don't trade on strokes alone
Combine with volume analysis
Use candlestick patterns at hub boundaries
Wait for breakout confirmation


Risk Management

Always place stops outside hub zones
Use hub width to size positions (wider hub = smaller position)
Exit if price re-enters broken hub from wrong direction


Avoid Common Pitfalls

Don't trade within central hubs (range-bound, unpredictable)
Don't ignore higher timeframe hub structures
Don't chase strokes after they've extended far from hub
Don't trust single-stroke hubs (need 3+ strokes for validity)



Performance Considerations

Max Bars Limit: Set to 3600 to balance detail with performance
Safe Distance Calculation: Only draws objects within 2000 bars of current price
Object Cleanup: Automatically removes old drawing objects to prevent memory issues
Efficient Arrays: Uses indexed arrays for fast lookup and processing

Ideal Market Conditions
Best Performance:

Liquid markets with clear structure (major forex pairs, indices, large-cap stocks)
Trending markets with periodic consolidations
Medium to high volatility for clear stroke formation

Less Effective:

Extremely choppy, directionless markets
Very low timeframes (< 5 minutes) with excessive noise
Illiquid instruments with erratic price action

Integration with Other Indicators
Complementary Tools:

Volume Profile: Confirm hub significance with volume nodes
Moving Averages: Use for trend bias within stroke structure
RSI/MACD: Momentum confirmation at hub boundaries
Fibonacci Retracements: Hub levels often align with Fib levels

Advantages
✓ Objective Structure: Removes subjectivity from market structure analysis
✓ Visual Clarity: Color-coded strokes and clear hub zones
✓ Multi-Timeframe Applicable: Works on all timeframes from minutes to months
✓ Complete Framework: Provides entry, exit, and risk management levels
✓ Theoretical Foundation: Based on proven Chan Theory methodology
✓ Customizable: Extensive parameter and visual customization options
Limitations
⚠ Learning Curve: Requires understanding of Chan Theory principles
⚠ Lag Factor: Strokes confirm after price movements complete
⚠ Parameter Sensitivity: Different settings produce significantly different results
⚠ Choppy Market Struggles: Can generate excessive hubs in range-bound conditions
⚠ Computation Intensive: May slow down on lower-end systems with max bars setting
Optimization Tips

Timeframe Selection

Scalping: 5-15 minute charts, lookback period 3-4
Day Trading: 15-60 minute charts, lookback period 4-5
Swing Trading: 4-hour to daily charts, lookback period 5-7
Position Trading: Daily to weekly charts, lookback period 7-10


Volatility Adjustment

High volatility: Increase minimum gap bars to reduce noise
Low volatility: Decrease lookback period to capture smaller moves


Visual Optimization

Use contrasting colors for different market conditions
Adjust line widths based on chart resolution
Toggle markers off for cleaner appearance once familiar with structure



Quick Start Guide
For Beginners:

Start with default settings (5 lookback, 4 min gap)
Enable "Show Info Table" to track stroke count
Focus on identifying clear hub formations
Practice waiting for price to break hub boundaries before trading

For Advanced Users:

Optimize lookback and gap parameters for your instrument
Use hub strokes (yellow) to identify key consolidation zones
Combine with multiple timeframes for confirmation
Develop entry rules based on hub breakout/retest patterns

This indicator provides a complete structural framework for understanding market behavior through the lens of Chan Theory, offering traders a systematic approach to identifying high-probability trading opportunities.

Отказ от ответственности

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.