OPEN-SOURCE SCRIPT

TraderDemircan Auto Fibonacci Retracement

49
Description:
What This Indicator Does:This indicator automatically identifies significant swing high and swing low points within a customizable lookback period and draws comprehensive Fibonacci retracement and extension levels between them. Unlike the manual Fibonacci tool that requires you to constantly redraw levels as price action evolves, this automated version continuously updates the Fibonacci grid based on the most recent major swing points, ensuring you always have current and relevant support/resistance zones displayed on your chart.Key Features:
Automatic Swing Detection: Continuously scans the specified lookback period to find the most significant high and low points, eliminating manual drawing errors
Comprehensive Level Coverage: Plots 16 Fibonacci levels including 7 retracement levels (0.0 to 1.0) and 9 extension levels (1.115 to 3.618)
Top-Down Methodology: Draws from swing high to swing low (right-to-left), following the traditional Fibonacci retracement convention where 100% is at the top
Dual Labeling System: Shows both exact price values and Fibonacci percentages for easy reference
Complete Customization: Individual toggle controls and color selection for each of the 16 levels
Flexible Display Options: Adjust line thickness (1-5), style (solid/dashed/dotted), and extension direction (left/right/both)
Visual Swing Markers: Red diamond at the swing high (starting point) and green diamond at the swing low (ending point)
Optional Trend Line: Connects the two swing points to visualize the overall price movement direction
How It Works:The indicator employs a sophisticated swing point detection algorithm that operates in two stages:Stage 1 - Find the Swing Low (Support Base):
Scans the entire lookback period to identify the lowest low, which becomes the anchor point (0.0 level in traditional retracement terms, though displayed at the bottom of the grid).Stage 2 - Find the Swing High (Resistance Peak):
After identifying the swing low, searches for the highest high that occurred after that low point, establishing the swing range. This creates a valid price movement range for Fibonacci analysis.Fibonacci Calculation Method:
The indicator uses the top-down approach where:

1.0 Level = Swing High (100% retracement, the top)
0.0 Level = Swing Low (0% retracement, the bottom)
Retracement Levels (0.236 to 0.786) = Potential support zones during pullbacks from the high
Extension Levels (1.115 to 3.618) = Potential target zones below the swing low
Formula: Price = SwingHigh - (SwingHigh - SwingLow) × FibonacciLevelThis ensures that 0.0 is at the bottom and extensions (>1.0) plot below the swing low, following standard Fibonacci retracement convention.Fibonacci Levels Explained:Retracement Levels (0.0 - 1.0):

0.0 (Gray): Swing low - the base support level
0.236 (Red): Shallow retracement, first minor support
0.382 (Orange): Moderate retracement, commonly watched support
0.5 (Purple): Psychological midpoint, significant support/resistance
0.618 (Blue - Golden Ratio): The most important retracement level, high-probability reversal zone
0.786 (Cyan): Deep retracement, last defense before full reversal
1.0 (Gray): Swing high - the initial resistance level
Extension Levels (1.115 - 3.618):

1.115 (Green): First extension, minimal downside target
1.272 (Light Green): Minor extension, common profit target
1.414 (Yellow-Green): Square root of 2, mathematical significance
1.618 (Gold - Golden Extension): Primary downside target, most watched extension level
2.0 (Orange-Red): 200% extension, psychological round number
2.382 (Pink): Secondary extension target
2.618 (Purple): Deep extension, major target zone
3.272 (Deep Purple): Extreme extension level
3.618 (Blue): Maximum extension, rare but powerful target
How to Use:For Retracement Trading (Buying Pullbacks in Uptrends):

Wait for price to make a significant move up from swing low to swing high
When price starts pulling back, watch for reactions at key Fibonacci levels
Most common entry zones: 0.382, 0.5, and especially 0.618 (golden ratio)
Enter long positions when price shows reversal signals (candlestick patterns, volume increase) at these levels
Place stop loss below the next Fibonacci level
Target: Return to swing high or higher extension levels
For Extension Trading (Profit Targets):

After price breaks below the swing low (0.0 level), use extensions as profit targets
First target: 1.272 (conservative)
Primary target: 1.618 (golden extension - most commonly reached)
Extended target: 2.618 (for strong trends)
Extreme target: 3.618 (only in powerful trending moves)
For Counter-Trend Trading (Fading Extremes):

When price reaches deep retracements (0.786 or below), look for exhaustion signals
Watch for divergences between price and momentum indicators at these levels
Enter reversal trades with tight stops below the swing low
Target: 0.5 or 0.382 levels on the bounce
For Trend Continuation:

In strong uptrends, shallow retracements (0.236 to 0.382) often hold
Use these as low-risk entry points to join the existing trend
Failure to hold 0.5 suggests weakening momentum
Breaking below 0.618 often indicates trend reversal, not just retracement
Multi-Timeframe Strategy:

Use daily timeframe Fibonacci for major support/resistance zones
Use 4H or 1H Fibonacci for precise entry timing within those zones
Confluence between multiple timeframe Fibonacci levels creates high-probability zones
Example: Daily 0.618 level aligning with 4H 0.5 level = strong support
Settings Guide:Lookback Period (10-500):

Short (20-50): Captures recent swings, more frequent updates, suited for day trading
Medium (50-150): Balanced approach, good for swing trading (default: 100)
Long (150-500): Identifies major market structure, suited for position trading
Higher values = more stable levels but slower to adapt to new trends
Pivot Sensitivity (1-20):

Controls how many candles are required to confirm a swing point
Low (1-5): More sensitive, identifies minor swings (default: 5)
High (10-20): Less sensitive, only major swings qualify
Use higher sensitivity on lower timeframes to filter noise
Individual Level Toggles:

Enable only the levels you actively trade to reduce chart clutter
Common minimalist setup: Show only 0.382, 0.5, 0.618, 1.0, 1.618, 2.618
Comprehensive setup: Enable all levels for maximum information
Visual Customization:

Line Thickness: Thicker lines (3-5) for presentation, thinner (1-2) for trading
Line Style: Solid for primary levels (0.5, 0.618, 1.618), dashed/dotted for secondary
Price Labels: Essential for knowing exact entry/exit prices
Percent Labels: Helpful for quickly identifying which Fibonacci level you're looking at
Extension Direction: Extend right for forward-looking analysis, left for historical context
What Makes This Original:While Fibonacci indicators are common on TradingView, this script's originality comes from:
Intelligent Two-Stage Detection: Unlike simple high/low finders, this uses a sequential approach (find low first, then find the high that occurred after it), ensuring logical price flow representation
Comprehensive Level Set: Includes 16 levels spanning from retracement to extreme extensions, more than most Fibonacci tools
Top-Down Methodology: Properly implements the traditional Fibonacci retracement convention (high to low) rather than the reverse
Automatic Range Validation: Only draws Fibonacci when both swing points are valid and in the correct temporal order
Dual Extension Options: Separate controls for extending lines left (historical context) and right (forward projection)
Smart Label Positioning: Places percentage labels on the left and price labels on the right for clarity
Visual Swing Confirmation: Diamond markers at swing points help users understand why levels are positioned where they are
Important Considerations:
Historical Nature: Fibonacci retracements are based on past price swings; they don't predict future moves, only suggest potential support/resistance
Self-Fulfilling Prophecy: Fibonacci levels work partly because many traders watch them, creating actual support/resistance at those levels
Not All Levels Hold: In strong trends, price may slice through multiple Fibonacci levels without pausing
Context Matters: Fibonacci works best when aligned with other support/resistance (previous highs/lows, moving averages, trendlines)
Volume Confirmation: The most reliable Fibonacci reversals occur with volume spikes at key levels
Dynamic Updates: The levels will redraw as new swing highs/lows form, so don't rely solely on static screenshots
Best Practices:
Don't Trade Blindly: Fibonacci levels are zones, not exact prices. Look for confirmation (candlestick patterns, indicators, volume)
Combine with Price Action: Watch for pin bars, engulfing candles, or doji at key Fibonacci levels
Use Stop Losses: Place stops beyond the next Fibonacci level to give trades room but limit risk
Scale In/Out: Consider entering partial positions at 0.5 and adding more at 0.618 rather than all-in at one level
Check Multiple Timeframes: Daily Fibonacci + 4H Fibonacci convergence = high-probability zone
Respect the 0.618: This golden ratio level is historically the most reliable for reversals
Extensions Need Strong Trends: Don't expect extensions to be hit unless there's clear momentum beyond the swing low
Optimal Timeframes:
Scalping (1-5 minutes): Lookback 20-30, watch 0.382, 0.5, 0.618 only
Day Trading (15m-1H): Lookback 50-100, all retracement levels important
Swing Trading (4H-Daily): Lookback 100-200, focus on 0.5, 0.618, 0.786, and extensions
Position Trading (Daily-Weekly): Lookback 200-500, all levels relevant for long-term planning
Common Fibonacci Trading Mistakes to Avoid:
Wrong Swing Selection: Choosing insignificant swings produces meaningless levels
Premature Entry: Entering as soon as price touches a Fibonacci level without confirmation
Ignoring Trend: Fighting the main trend by buying deep retracements in downtrends
Over-Reliance: Using Fibonacci in isolation without confirming with other technical factors
Static Analysis: Not updating your Fibonacci as market structure evolves
Arbitrary Lookback: Using the same lookback period for all assets and timeframes
Integration with Other Tools:Fibonacci + Moving Averages:

When 0.618 level aligns with 50 or 200 EMA, confluence creates stronger support
Price bouncing from both Fibonacci and MA simultaneously = high-probability trade
Fibonacci + RSI/Stochastic:

Oversold indicators at 0.618 or deeper retracements = strong buy signal
Overbought indicators at swing high (1.0) = potential reversal warning
Fibonacci + Volume Profile:

High-volume nodes aligning with Fibonacci levels create robust support/resistance
Low-volume areas near Fibonacci levels may see rapid price movement through them
Fibonacci + Trendlines:

Fibonacci retracement level + ascending trendline = double support
Breaking both simultaneously confirms trend change
Technical Notes:
Uses ta.lowest() and ta.highest() for efficient swing detection across the lookback period
Implements dynamic line and label arrays for clean redraws without memory leaks
All calculations update in real-time as new bars form
Extension options allow customization without modifying core code
Format.mintick ensures price labels match the symbol's minimum price increment
Tooltip on swing markers shows exact price values for precision

Feragatname

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.