INVITE-ONLY SCRIPT

ChanLun Pro

Updated
ChanLun, also known as Entanglement Theory or "缠论", is a highly regarded technical analysis methodology that originated in China. Since its introduction in 2006, ChanLun has rapidly gained significant attention and a strong following within the Chinese trader community due to its exceptional ability to navigate complex market dynamics.

ChanLun places great emphasis on market structure, price action, momentum, and the intricate interplay between market forces. It recognizes that the market operates in cyclical patterns and aims to capture the underlying structure and rhythm of price movements. Through meticulous analysis of the intricate relationships between price and time, it provides traders with a unique perspective on market trends, potential reversals, and critical turning points.

This indicator offers a meticulous and comprehensive implementation of the ChanLun theory. It facilitates in-depth analysis and visual representation of all essential components, encompassing “Candlestick Conversion”, "Candlestick Standardization", "Fractal", "Stroke", "Segment", "Pivot", and "Buying/Selling Point".

🟠 Algorithm

🔵 Step 1: Candlestick Conversion

In ChanLun, candlestick analysis focuses less on the opening/closing prices and wicks, but rather emphasizes the price range at which the stock price has reached. As a result, the initial step in ChanLun involves converting each candlestick to contain solely the high and low prices, disregarding other elements.

snapshot

🔵 Step 2: Candlestick Standardization

In the second step, the converted candlesticks are standardized to ensure strict directional consistency and eliminate the presence of inner bars or outer bars. For any adjacent two candlesticks A and B where one’s price range completely encompasses another, A and B are merged into a new candlestick C. If A is trending up from its previous candle, then C will be defined such that high(C) = max(high(A), high(B)) and low(C) = max(low(A), low(B)). If A is trending down from its previous candle, then C will be defined such that high(C) = min(high(A), high(B)) and low(C) = min(low(A), low(B)).

snapshot

After completing these steps, when considering any adjacent candlesticks A and B, we can always observe either of the following conditions:

1. high(A) > high(B) and low(A) > low(B)
2. high(A) < high(B) and low(A) < low(B)

The chart below illustrates how the candlesticks would appear after this step.

snapshot

🔵 Step 3: Fractals

A "Fractal" refers to the pattern formed by three consecutive "standardized" candlesticks, where the middle candlestick shows a clear higher or lower value compared to the surrounding candlesticks. When considering three adjacent candlesticks, A, B, and C, we have either of the two conditions:

1. high(B) > high(A) and high(B) > high(C) and low(B) > low(A) and low(B) > low(C)
2. high(B) < low(A) and high(B) < low(C) and low(B) < low(A) and low(B) < low(C)

For #1 above, we refer to the combination of A, B, and C as a “Top Fractal”, whereas for #2 we designate it as a “Bottom Fractal”.

The chart below illustrates all the fractals, with the red triangles indicating the Top Fractals and the green triangles indicating the Bottom Fractals.

snapshot

🔵 Step 4: Strokes

A “Stroke” is a line connecting a top fractal and a bottom fractal, subject to the following rules:

1. There must be at least one "free" candlestick positioned between these fractals, meaning it is not part of either the top or bottom fractal. This guarantees that a stroke encompasses a minimum range of five candlesticks from beginning to end.
2. The top fractal must have a higher price compared to the bottom fractal.
3. The endpoint fractals should represent the highest or lowest point throughout the entire span of the stroke. (There is an option within this indicator to enable or disable this rule.)

snapshot

Strokes enable traders to identify and visualize significant price swings or trends while effectively filtering out minor fluctuations.

🔵 Step 5: Segments

A "Segment" is a higher-level line that connects the starting and ending points of at least three consecutive strokes, reflecting the current trend of the market structure. It continues to extend as new strokes emerge, until there is a break in the market structure. The break occurs when an uptrend forms a lower high and lower low, or when a downtrend forms a higher high and higher low. It's worth noting that during trading ranges, it is common for strokes to exhibit a higher high and lower low or a higher low and lower high pattern (similar to inner bars and outer bars). In such cases, the strokes will be merged in a similar manner as described earlier for candlesticks, until there is a distinct break in the market structure. Segments provide a relatively stable depiction of the market trend in a higher timeframe, as opposed to strokes.

snapshot

It is important to note that the algorithm used to calculate segments from strokes can be recursively applied to the generated segments again, forming higher-level segments that represent the market trend on a even larger timeframe.

snapshot

🔵 Step 6: Pivots

In ChanLun, the term "Pivot" does not indicate a price reversal point. Instead, it represents a trading range where the price of a security tends to fluctuate. Within a given "Segment," the pivot is determined by the overlap of two consecutive strokes moving in the opposite direction of the segment. When two downtrend strokes A and B form a pivot P within an uptrend segment S, the upper and lower bounds of the pivot are defined as follows:

1. upper(P) = min(high(A), high(B)
2. lower(P) = max(low(A), low(B))

The pivot range is typically where consolidation occurs and where there is a high trading volume.

If a future stroke, moving in the opposite direction of the current segment, overlaps with the upper and lower bounds of the pivot, it is merged into the existing pivot and extends the pivot along the x-axis. A new pivot is formed when two consecutive strokes moving in the opposite direction of the current segment, intersect with each other without overlapping the previous pivot.

snapshot

Likewise, pivots can also be recursively identified within the higher-level segments. The blue boxes below represent the "Segment Pivots" that are identified within the context of higher-level segments.

snapshot

🔵 Step 7: Buying/Selling Points

There are three types of buying/selling points defined in ChanLun.

1. Type 1 Buying and Selling Points: Also known as trend reversal points. These points are where the old segments terminate and new segments are generated.
2. Type 2 Buying and Selling Points: Also known as trend continuation points. These points occur while the price is in the midst of a trend and signify the continuation of the trend. In an uptrend, the Type 2 buying point is the rebound point after the price retraces to a previous low or support level, indicating that the price may continue to rise. In a downtrend, the Type 2 selling point is the pullback point after the price rallies to a previous high or resistance level, indicating that the price may continue to decline.
3. Type 3 Buying and Selling Points: These points indicate the retests of breakouts from pivot ranges. The presence of these retest points suggests that the price has the potential to continue its upward/downward movement above/below the pivot levels.

snapshot

A discerning reader may notice that these buying/selling points are lagging indicators. For example, by the time a new segment is confirmed, multiple candlesticks have already occurred since the type 1 buying/selling point of that segment.
Indeed, it is true that the buying/selling points lag behind the actual market movements. However, ChanLun addresses this issue through the utilization of multi-timeframe analysis. By examining the confirmed buying/selling points in a lower timeframe, one can gather additional confidence in determining the overall trend of the higher timeframe.

🔵 Step 8: Divergence

Another core technique in ChanLun is the application of divergence to anticipate the emergence of type 1 buying/selling points. While MACD is the most commonly employed indicator for detecting divergence, other indicators such as RSI can also be utilized for this purpose.

snapshot

🟠 Summary

In essence, ChanLun is a robust approach to technical analysis that integrates the careful examination and interpretation of price charts, the application of technical indicators and quantitative tools, and a keen attention to multiple timeframes. Its objective is to identify prevailing market trends and uncover potential trading prospects. What sets ChanLun apart is its holistic methodology, which blends both qualitative and quantitative analysis to facilitate informed and successful trading decisions.

🟠 NOTE

The freely available "ChanLun | AlgoTrader" script, published by the same account, incorporates only a limited set of fundamental concepts from ChanLun.
In contrast, this script is a premium invite-only version that represents a comprehensive implementation of the complete ChanLun methodology, specifically tailored for more experienced and professional traders.

________________________________________________________________________________


该指标严格按照缠论原文实现了包括“K线标准化”、“分型”、“笔”、“线段”、“中枢”和“买卖点”在内的所有关键元素。它旨在为缠友们提供一个准确可靠的缠论实现,以便快速而精准地分析市场,从而获得更优秀的交易业绩。

该指标的主要特点如下:

1. 实时标记所有缠论元素:该指标具备实时识别和标记分型、笔、线段、中枢和买卖点的功能,提供清晰的信号和准确的趋势判断。
2. 多种笔段算法选择:提供三种不同的笔算法(“老笔”、“新笔”和“4K”)以及两种线段算法(“特征序列”和“1+1终结”),满足不同交易者个性化需求,可根据偏好和策略选择最适合的算法。
3. 三级别联立:指标同步计算并显示笔、线段和递归高级段,提供更全面的市场动态分析。
4. 自定义颜色:用户可以根据个人喜好和需求自定义指标的颜色方案,与图表风格和视觉需求完美匹配。
5. 完美实现K线回放功能:指标充分利用了K线回放功能,让交易者能够回顾和分析历史市场数据,提高对市场趋势的研究和理解,增强市场洞察力和决策能力。
Release Notes
- Make the default value for "Allow Second-highest/lowest Endpoints" to "Disallow"
- Bug fix.
_________________________________________________________________________

- 默认不允许“次高次低点”成笔
- 修复 bug
Release Notes
- Added support for toggling the level of buying/selling points.
- Resolved an issue where the algorithm did not function properly for the GER30 1M chart.
────────────────────────────────────────────
- 增加切换买卖点级别的功能
- 解决在 GER30 一分钟图上算法异常的问题
Release Notes
Added support for "pivot expansion", where two pivots in the same trend have overlapped price ranges, and forms a higher-level pivot.
增加对“中枢扩张”的支持:两个同向同级别中枢有价格区间的重叠,产生更高级别的中枢。

snapshot
Release Notes
- Conceal the input values in the status bar to enhance chart clarity.
- 在状态栏中隐藏指标参数,以使图表更加清晰。
Release Notes
Version 2.0

- Optimized, redesigned, and reimplemented the core algorithm for strokes and segments for maximum accuracy and efficiency.
- Implemented the "Stroke Correction" concept to ensure that the endpoints for each stroke are strictly the highest and lowest points for all the candles (after "standardization/merge") encompassed by the stroke.
- Added a new option to limit the number of candles to analyze, which can be used to achieve better script performance.
- Added visualization for trait sequences.
────────────────────────────────────────────
- 重新实现并大幅优化笔和线段的核心算法以使系统更加准确及稳健。
- 实现“修正笔”算法,以严格确保每笔的起始点和终止点是该笔的所有K线(“标准化 / 包含”处理后)的最高和最低点。
- 新增选项以控制需要分析的历史K线数量。该选项可用来提升脚本性能。
- 新增“特征序列”的可视化。
Release Notes
Version 2.1

- Fixed an runtime exception in the NKD 15M chart, caused by the segment state not being properly restored during stroke correction.
────────────────────────────────────────────
- 修正在 NKD 15 分图中会产生的一个运行异常。该异常由于在处理修正笔时未能正确恢复之前线段的状态所导致。
Release Notes
Version 2.2

- Fixed an runtime exception in the XAUUSD 15M chart, caused by an incorrect assertion during pivot calculation.
────────────────────────────────────────────
- 修复了 XAUUSD 15分钟图中的运行异常,该异常是由于在计算中枢时出现了错误的断言所导致。
Release Notes
Version 2.3

- Added support for highlighting upgraded pivots that are extending at or beyond 9 strokes.
- Fixed an issue where the endpoints of two consecutive segments may have gaps between them.
────────────────────────────────────────────
- 增加对中枢升级(延伸9笔或更多)的高亮支持。
- 修复一个两连续线段中间可能产生空隙的错误。
Release Notes
Version 2.4

- Fixed an issue where the "1+1 Termination" Segment algorithm was returning incorrect segments.
────────────────────────────────────────────
- 修复 “1+1 终结” 线段算法。
Release Notes
Version 3.0

- Introduced the capability for multi-level trend recursion, empowering users to define a custom A0 (initial recursion point) and automatically generate the trends up to the current level.
────────────────────────────────────────────
- 新增对多重走势递归的支持。允许用户自定义 A0 (递归起点)并自动递归走势至当前级别。
Release Notes
Version 3.1

- Fixed minor issues with pivots and buying / selling points.
────────────────────────────────────────────
- 修正关于中枢和买卖点的问题。
Release Notes
Version 3.2

- Worked around two issues identified in the latest TradingView PineScript runtime that broke this indicator.
────────────────────────────────────────────
- 绕开 TradingView 最新运行环境引入了的两个导致指标失效的 bug。

请从主图上删除该指标并重新添加以更新到最新版本。谢谢!
Release Notes
Version 4.0

- Added an option to enable special treatment of strong strokes that break the high/low of preceding segments. When a stroke breaks the high/low of its immediate preceding segment that runs in the opposite direction, allow either "Single-Stroke Segment" (generate a new segment from the stroke) or "Segment Extension" (remove the segment and extend the preceding one).
- Optimized trend segmentation algorithm.
- Fixed minor issues with 1+1 termination, buying/selling points, and recursion.
────────────────────────────────────────────
- 新增选项以特殊处理强势笔。当一笔突破相连的前一反向线段的高低点时,允许“单笔成段”(该笔直接成为一个新的线段)或者“线段延伸”(删除当下线段并延伸前一线段到该笔终结处)。
- 优化走势划分算法。
- 修复关于“1+1终结”,“买卖点”,和“递归”的一些小问题。
Release Notes
Version 4.1

- Fixed coloring issue with current-level pivots.
- Fixed display issue with expanded pivots.
────────────────────────────────────────────
- 修复本级别中枢的着色问题。
- 修复中枢扩张的显示问题。
Release Notes
Version 4.2

- Added back missing updates that are supposed to be in V4.1.
────────────────────────────────────────────
- 重新添加本应属于 4.1 版本的改动。
Release Notes
Version 5.0

- Introduced an enhanced movement decomposition algorithm that's strictly based on pivot zone analysis. This new algorithm can be enabled by selecting the "Pivot-based" option in the "Movement Algorithm" setting.
- Due to tighter resource constraints with a new version of the TradingView platform, recursion settings have been temporarily disabled. Support for recursion will be re-enabled once further optimizations are completed to streamline the algorithm's resource usage.
- "Segment Extension" is now the default handling approach for strong strokes that break the high/low of a preceding segment.
- Resolved multiple minor issues.

────────────────────────────────────────────

- 新增严格基于中枢的走势划分算法。该算法使用”中枢维持“及”非同级别分解“思路。请将指标设置界面中的“走势划分算法”选项改为“按中枢”来使用该算法。
- 由于新版 TradingView 平台大幅降低了指标允许使用的 CPU 和内存资源,从小周期开始的递归模式将无法使用。因此,暂时隐藏递归选项。该选项将在以后算法优化后重新提供。
- 默认使用“线段延伸”作为强势笔的处理方法。
- 修复另外几个小问题。
Release Notes
Version 6.0

- Improved calculation performance by 100%.
- Significantly reduced memory consumption and no longer triggering the memory-exceeded error.
- Introduced buying / selling points for the pivot-based decomposition mode.
- Introduced a new stroke mode, 'fractal stroke', which immediately forms a stroke whenever there's a fractal pair, without any minimal requirement on the number of candles.
────────────────────────────────────────────
- 指标计算性能提升为之前版本的 2 倍。
- 大幅减少内存占用。不再触发“内存使用超出限制”的错误。
- 针对“基于中枢的走势划分”模式,新增买卖点显示。
- 新增一个笔模式:“分型笔”(相邻顶底分型直接成笔,无最小K线数量要求)。
Release Notes
Version 6.1

- Fix a couple minor bugs with strokes and pivots.
────────────────────────────────────────────
- 修复笔和中枢的一些小问题。
Release Notes
Version 7.0

- Added support for alerts on buying / selling points.
- Enhanced display capabilities to show both current and sub-level buying and selling points.
- Reintroduced the A0 timeframe settings, originally introduced in V3.0, to support recursion from a lower timeframe.
- Optimized the segment and movement algorithm.

────────────────────────────────────────────

- 新增买卖点警报功能。
- 新增同时显示本级别和次级别买卖点的功能。
- 重新添加之前在 3.0 版本中提供的 A0 时间周期设置。使得指标可从指定的小周期递归上来。
- 优化线段及走势算法。
Candlestick analysischanchanlunmarketstructuremultitimeframeanalysissignalsswingTrend AnalysistrendtradingWave AnalysisZEN

Invite-only script

Access to this script is restricted to users authorized by the author and usually requires payment. You can add it to your favorites, but you will only be able to use it after requesting permission and obtaining it from its author. Contact AlphaViz for more information, or follow the author's instructions below.

TradingView does not suggest paying for a script and using it unless you 100% trust its author and understand how the script works. In many cases, you can find a good open-source alternative for free in our Community Scripts.

Author's instructions

请访问 https://alphaviz.pro/chanlun 以获取权限(订阅时自动获得 7 天免费试用)。 Gain access to script at https://alphaviz.pro/chanlun

Want to use this script on a chart?

Warning: please read before requesting access.

专业缠论指标: alphaviz.pro/chanlun
Email: contact@alphaviz.pro
Discord: discord.gg/w2fFtNega4
Also on:

Disclaimer