Double Top/Bottom Detector with Williams Fractals (Extended + Early Signal)
This indicator combines the classic Williams Fractals methodology with an enhanced mechanism to detect potential reversal patterns—namely, double tops and double bottoms. It does so by using two separate detection schemes:
Confirmed Fractals for Pattern Formation:
The indicator calculates confirmed fractals using the traditional Williams Fractals rules. A fractal is confirmed if a bar’s high (for an up fractal) or low (for a down fractal) is the highest or lowest compared to a specified number of bars on both sides (default: 2 bars on the left and 2 on the right). Once a confirmed fractal is identified, its price (high for tops, low for bottoms) and bar index are stored in an internal array (up to the 10 most recent confirmed fractals). When a new confirmed fractal appears, the indicator compares it with previous confirmed fractals. If the new fractal is within a user-defined maximum bar distance (e.g., 20 bars) and the price difference is within a specified tolerance (default: 0.8%), the indicator assumes that a double top (if comparing highs) or a double bottom (if comparing lows) pattern is forming. A signal is then generated by placing a label on the chart—SELL for a double top and BUY for a double bottom. Early Signal Generation:
To capture potential reversals sooner, the indicator also includes an “early signal” mechanism. This uses asymmetric offsets different from the confirmed fractal calculation: Signal Right Offset: Defines the candidate bar used for early signal detection (default is 1 bar). Signal Left Offset: Defines the number of bars to the left of the candidate that must confirm the candidate’s price is the extreme (default is 2 bars). For an early top candidate, the candidate bar’s high must be greater than the highs of the bars specified by the left offset and also higher than the bar immediately to its right. For an early bottom candidate, the corresponding condition applies for lows. If the early candidate’s price level is within the acceptable tolerance when compared to any of the previously stored confirmed fractals (again, within the allowed bar distance), an early signal is generated—displayed as SELL_EARLY or BUY_EARLY. The early signal block can be enabled or disabled via a checkbox input, allowing traders to choose whether to use these proactive signals. Key Parameters:
n: The number of bars used to confirm a fractal. The fractal is considered valid if the bar’s high (or low) is higher (or lower) than the highs (or lows) of the preceding and following n bars.
maxBarsApart: The maximum number of bars allowed between two fractals for them to be considered part of the same double top or bottom pattern.
tolerancePercent: The maximum allowed percentage difference (default: 0.8%) between the high (or low) values of two fractals to qualify them as matching for the pattern.
signalLeftOffset & signalRightOffset: These parameters define the asymmetric offsets for early signal detection. The left offset (default: 2) specifies how many bars to look back, while the right offset (default: 1) specifies the candidate bar’s position.
earlySignalsEnabled: A checkbox option that allows users to enable or disable early signal generation. When disabled, the indicator only uses confirmed fractal signals.
How It Works:
Fractal Calculation and Plotting: The confirmed fractals are calculated using the traditional method, ensuring robust identification by verifying the pattern with a symmetrical offset. These confirmed fractals are plotted on the chart using triangle shapes (upwards for potential double bottoms and downwards for potential double tops).
Pattern Detection: Upon detection of a new confirmed fractal, the indicator checks up to 10 previous fractals stored in internal arrays. If the new fractal’s high or low is within the tolerance range and close enough in terms of bars to one of the stored fractals, it signifies the formation of a double top or double bottom. A corresponding SELL or BUY label is then placed on the chart.
Early Signal Feature: If enabled, the early signal block checks for candidate bars based on the defined asymmetric offsets. These candidates are evaluated to see if their high/low levels meet the early confirmation criteria relative to nearby bars. If they also match one of the confirmed fractal levels (within tolerance and bar distance), an early signal is issued with a label (SELL_EARLY or BUY_EARLY) on the chart.
Benefits for Traders:
Timely Alerts: By combining both confirmed and early signals, the indicator offers a proactive approach to detect reversals sooner, potentially improving entry and exit timing.
Flexibility: With adjustable parameters (including the option to disable early signals), traders can fine-tune the indicator to better suit different markets, timeframes, and trading styles.
Enhanced Pattern Recognition: The dual-layered approach (confirmed fractals plus early detection) helps filter out false signals and captures the essential formation of double tops and bottoms more reliably.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.