OPEN-SOURCE SCRIPT

Dynamic Trend-Based Fibonacci Extension

168
💡 This indicator is a sophisticated, automated technical analysis tool designed to identify high-probability trend continuation setups using the principles of market structure and Fibonacci geometry. By algorithmically detecting "A-B-C" price structures (Pivot -> Impulse -> Retracement), it projects dynamic Fibonacci Extension levels to forecast potential price targets for the next impulsive move (Wave C to D). Unlike static drawing tools, this script adapts to market volatility and features an advanced invalidation engine to keep your charts clean and your risk managed.

✨ Originality and Utility

Traders often struggle with the subjectivity of drawing Fibonacci extensions manually. This script solves that by standardizing the identification of market structure using a proprietary ZigZag algorithm enhanced with Average True Range (ATR) for volatility-adjusted sensitivity.



Key unique features include:
  • Automated Structure Detection: Instantly spots Bullish (Higher High, Higher Low) and Bearish (Lower Low, Lower High) sequences without manual input.
  • Dynamic Invalidation: The script monitors price action in real-time. If price breaks the invalidation point (Point A), the structure is immediately "grayed out" or deleted, preventing you from trading based on broken setups.
  • Golden Zone Targeting: Highlights the high-probability reversal zone between the 1.5 and 1.618 extensions, often associated with the completion of a measured move.
  • JSON Alerting: Built-in support for algorithmic trading with structured JSON payloads (Entry, TP, SL) ready for webhook integration.


🔬 Methodology and Concepts

The core logic operates on a three-step algorithmic sequence:

  • 1. Pivot Identification: The script uses a "ZigZag" approach to find significant swing highs and lows. It employs an ATR-based threshold (or fixed deviation) to filter out market noise, ensuring only significant structural points are considered.
  • 2. Geometric Validation: It evaluates the last three pivot points (A, B, C) to confirm a valid trend structure.
    Bullish Setup: Point C must be higher than Point A but lower than Point B (a valid retracement).
    Bearish Setup: Point C must be lower than Point A but higher than Point B.
  • 3. Projection Mathematics: Once a valid ABC structure is locked, the script calculates extension targets using the standard formula: Target = Price C + ((Price B - Price A) * Ratio). It also supports Logarithmic Scale calculations for assets with exponential growth, such as cryptocurrencies, ensuring proportional accuracy over large price ranges.



🎨 Visual Guide

The indicator paints a clear, detailed roadmap on your chart. Here is how to interpret the visual elements:
快照
● Structure Lines
  • Solid Line (A to B): Represents the initial "Impulse" leg of the move.
  • Dashed Line (B to C): Represents the "Retracement" or corrective leg.
  • Green Structures: Indicate Bullish setups (looking for long entries).
  • Red Structures: Indicate Bearish setups (looking for short entries).
    快照
  • Gray/Dimmed Structures: These are invalidated setups where the price has breached the Stop Loss level (Point A).


● Extension Levels (Targets)
The script projects the following key Fibonacci ratios extending from Point C:
  • 0.618 (Wave 5): An early profit-taking level, often corresponding to a truncated 5th wave.
  • 1.0 (Measured Move): Where the extension equals the length of the initial impulse (AB = CD pattern).
  • 1.272 (Harmonic): A common extension level for corrective structures or deep pullbacks.
  • Golden Zone (1.5 - 1.618): A highlighted fill area. The 1.618 level (Solid Line) is the "Golden Ratio" and is statistically one of the most significant targets in trending markets, often labeled as "Wave 3".

快照
● Labels
  • Points A, B, C: Clearly marks the swing points defining the structure.
  • Right-Side Labels: Display the Ratio (e.g., 1.618) and the exact Price Level for easy order placement.


📖 How to Use

This tool is best used as a trend-following system.

1. Trend Identification
Wait for a new Solid Colored Structure (Green or Red) to appear. This confirms that a valid ABC retracement has occurred.

2. Entry Strategy
The "Trigger" is generally the reversal from Point C. Aggressive traders enter near C, while conservative traders may wait for a breakout above B.
Stop Loss: Place your SL just beyond Point A. If price breaks A, the script will automatically gray out the structure, signaling invalidation.

3. Profit Taking
Use the projected extension lines as dynamic Take Profit (TP) zones:
  • TP1: 1.0 (The Measured Move).
  • TP2: The Golden Zone (1.5 to 1.618). This is often the strongest target for a Wave 3 impulsive move.


4. Automation
For automated traders, create an alert using the "Any alert() function call" option. The script outputs a JSON string containing the Action, Ticker, Entry Price, TP (1.618), and SL (Point A).

⚙️ Inputs and Settings

You can fully customize the script to fit your asset class and timeframe:

● ZigZag Detection
  • Pivot Lookback Depth: (Default: 5) Determines how many bars to check left/right for a pivot. Higher numbers find larger, more significant structures.
  • Use ATR-Based Threshold: (Default: True) Adapts the sensitivity to market volatility.
  • ATR Multiplier: (Default: 2.0) Adjusts how much price must reverse to form a new leg.


● Structure Invalidation
  • Enable Structure Invalidation: (Default: True) Toggles the logic that checks if Point A is breached.
  • Invalidation Action: Choose "Gray Out" to keep history visible but dimmed, or "Delete" to remove failed setups entirely.


● Fibonacci Settings
  • Use Logarithmic Scale: Essential for crypto or long-term timeframe analysis.
  • Show 0.618 / 1.0 / 1.272 / 1.618: Toggles individual levels on/off to declutter the chart.
  • Extend Lines Right: Extends the target lines into the future for better visibility.


● Display Settings
  • Keep Last N Structures: Controls how many historical structures remain on the chart to prevent visual clutter.
  • Show Elliott Wave Labels: Adds theoretical wave counts (e.g., "Wave 3") to the ratio labels.


🔍 Deconstruction of the Underlying Scientific and Academic Framework

This indicator is grounded in Fractal Market Geometry and Elliott Wave Theory.

1. The Golden Ratio (Phi - 1.618):
Mathematically derived from the Fibonacci sequence, the 1.618 ratio is omnipresent in natural growth patterns. In financial markets, it represents the psychological "tipping point" of crowd behavior during an impulsive trend. This script emphasizes the 1.618 extension as the primary target for a "Wave 3," which is academically cited as typically the longest and strongest wave in a 5-wave motive sequence.

2. Harmonic AB=CD Patterns:
The inclusion of the 1.0 extension validates the "Measured Move" concept. Statistically, markets often move in symmetrical legs where the secondary impulse (CD) equals the magnitude of the primary impulse (AB).

3. Volatility Normalization (ATR):
By utilizing the Average True Range (ATR) for pivot detection, the script adheres to statistical volatility normalization. This ensures that the structures identified are statistically significant relative to the asset's current volatility regime, rather than relying on arbitrary percentage moves which fail across different asset classes.

⚠️ Disclaimer

All provided scripts and indicators are strictly for educational exploration and must not be interpreted as financial advice or a recommendation to execute trades. I expressly disclaim all liability for any financial losses or damages that may result, directly or indirectly, from the reliance on or application of these tools. Market participation carries inherent risk where past performance never guarantees future returns, leaving all investment decisions and due diligence solely at your own discretion.

免责声明

这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。