This Pine Script code implements Fibonacci retracement and extension levels based on a ZigZag pattern. Below is a breakdown of its functionality:
Overview The script calculates Fibonacci retracement and extension levels by identifying swing highs and swing lows using the ZigZag algorithm. It then plots these levels on the chart for trend analysis.
1. ZigZag Length Input Defines the ZigZag length, which determines the sensitivity of peak and trough identification.
2. Fibonacci Retracement Calculation Computes Fibonacci retracement levels using swing highs and lows. Uses pre-defined Fibonacci ratios (0.236, 0.382, 0.5, 0.618, 0.786, 1.0). Adjusts line positions dynamically as the trend evolves.
4. Trend and Fibonacci Configuration Allows the user to configure Fibonacci trend analysis. TrendSw: Sets the trend direction (1 = Bullish, -1 = Bearish, 0 = None). ZigZagleg: Determines the countback value for retracement calculations.