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".
🔵 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.
🔵 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)).
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.
🔵 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.
🔵 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.)
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.
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.
🔵 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.
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.
🔵 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.
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.
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.
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.
- Bug fix.
- 修复 bug
- Resolved an issue where the algorithm did not function properly for the GER30 1M chart.
- 解决在 GER30 一分钟图上算法异常的问题
- 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线（“标准化 / 包含”处理后）的最高和最低点。
- Fixed an runtime exception in the NKD 15M chart, caused by the segment state not being properly restored during stroke correction.
- 修正在 NKD 15 分图中会产生的一个运行异常。该异常由于在处理修正笔时未能正确恢复之前线段的状态所导致。
- Fixed an runtime exception in the XAUUSD 15M chart, caused by an incorrect assertion during pivot calculation.
- 修复了 XAUUSD 15分钟图中的运行异常，该异常是由于在计算中枢时出现了错误的断言所导致。
- 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.
- Fixed an issue where the "1+1 Termination" Segment algorithm was returning incorrect segments.
- 修复 “1+1 终结” 线段算法。
- 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 （递归起点）并自动递归走势至当前级别。
- Fixed minor issues with pivots and buying / selling points.
- Worked around two issues identified in the latest TradingView PineScript runtime that broke this indicator.
- 绕开 TradingView 最新运行环境引入了的两个导致指标失效的 bug。
- 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.
- Fixed coloring issue with current-level pivots.
- Fixed display issue with expanded pivots.
- Added back missing updates that are supposed to be in V4.1.
- 重新添加本应属于 4.1 版本的改动。
- 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 和内存资源，从小周期开始的递归模式将无法使用。因此，暂时隐藏递归选项。该选项将在以后算法优化后重新提供。
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 algotraderdev 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.
Warning: please read before requesting access.