Automatic Fibonacci Levels [WillyAlgoTrader]Automatic Fibonacci Levels is an overlay indicator that detects the dominant swing high and swing low within the visible chart area, draws a full Fibonacci retracement and extension grid between them, highlights the Optimal Trade Entry (OTE) zone at 61.8%–78.6%, marks a target zone at the −50% to −61.8% extension, and labels four take-profit levels — all updating automatically as you scroll or zoom the chart.
Most Fibonacci tools on TradingView are either manual (you draw them yourself and they become stale as price evolves) or pivot-based (anchored to a fixed lookback period that may not match the swing you're actually looking at). This indicator takes a different approach: it uses the visible chart range as its context. It finds the highest high and lowest low within what you can currently see, determines trend direction based on which came first, and draws the full Fibonacci grid accordingly. When you scroll or zoom to a different area, the grid adapts — making it a dynamic analysis companion rather than a static drawing tool.
🔍 WHAT MAKES IT ORIGINAL
1. Visible-range swing detection. Instead of using a fixed pivot lookback or requiring manual anchor placement, the indicator scans the chart's visible window (chart.left_visible_bar_time to chart.right_visible_bar_time) to find the absolute high and low. This means the Fibonacci grid always reflects the swing structure you are currently analyzing. Zoom into a 50-bar range to see intraday retracements; zoom out to 500 bars to see the macro structure — the grid adjusts automatically. When the visible range changes (scroll or zoom), swing detection resets and recalculates.
2. Automatic trend direction from swing sequence. The indicator determines bullish or bearish bias by comparing when the swing low and swing high occurred. If the swing low formed first and the swing high formed later, the trend is classified as bullish (retracement levels are drawn down from the high, extensions project upward). If the swing high came first, the trend is bearish (retracement down from the low, extensions project downward). No manual input is needed — the grid orientation follows the price structure.
3. OTE Entry Zone + Target Zone as highlighted boxes. Two key zones are highlighted with semi-transparent boxes:
— Entry Zone (61.8%–78.6%) : the Optimal Trade Entry area from ICT/SMC methodology — the deep retracement zone where institutional re-entry is most likely
— Target Zone (−50% to −61.8%) : the extension zone where breakout moves frequently reach
Both zones have configurable colors and optional text labels ("ENTRY ZONE" / "TARGET ZONE") inside them. Zone-touch alerts fire when price enters either box for the first time.
4. Four labeled take-profit levels. TP labels are placed at key Fibonacci levels to provide a structured scale-out framework:
— TP1 at 38.2% (first retracement target — conservative exit)
— TP2 at 0% (full swing retest — swing high in uptrend, swing low in downtrend)
— TP3 at −27.2% (first Fibonacci extension)
— TP4 at −61.8% (deep extension — runner target)
Each TP level is only displayed if the corresponding Fibonacci line is enabled, keeping the chart clean.
5. 16 individually toggleable levels. The indicator supports a comprehensive set of levels: 0%, 23.6%, 38.2%, 50%, 61.8%, 70.6%, 78.6%, 100% (standard retracements), plus 18%, 150%, 200% (deep retracements), and −18%, −27.2%, −50%, −61.8%, −100% (extensions). Each level can be toggled on or off independently, so you can configure exactly the grid density you prefer — from a minimal 4-level setup to a full 16-level deep analysis.
⚙️ HOW IT WORKS
Swing detection:
On every bar, the script checks whether the current bar falls within the chart's visible time window (using chart.left_visible_bar_time and chart.right_visible_bar_time). Within this window, it tracks the highest high and lowest low, along with their bar indices. When the visible window changes (scroll/zoom), all swing data resets and recalculates from scratch. This ensures the grid always reflects your current view.
Trend direction:
If swingLowBarIdx < swingHighBarIdx (low came first), the trend is classified as bullish — Fibonacci levels count downward from the swing high (0% = high, 100% = low), and extensions project above the high. If the high came first, the trend is bearish — levels count upward from the swing low, extensions project below.
Level calculation:
Each Fibonacci level is calculated as: price = anchor ± (swingRange × ratio), where the anchor and direction depend on the trend bias. For a bullish trend: 0% = swingHigh, 61.8% = swingHigh − range × 0.618, −50% = swingHigh + range × 0.5. For bearish: mirrored.
Zone detection:
The Entry Zone (61.8%–78.6%) and Target Zone (−50% to −61.8%) are computed as price ranges. On each confirmed bar, the script checks if the close falls within either zone. A zone-touch alert fires on the first confirmed bar inside the zone (no repeated alerts while price stays in the zone). The inEntryZone / inTargetZone state resets when price leaves, allowing re-entry detection.
Drawing:
All visual elements (lines, labels, boxes) are drawn on barstate.islast and cleaned up on each redraw to prevent accumulation. Lines extend from 2 bars before the current bar to the label offset position. Zones use extend.right so they remain visible as new bars form.
📖 HOW TO USE
Reading the chart:
— Orange horizontal lines = Fibonacci levels (retracement + extensions)
— Optional % labels next to each line = level identification
— Gold semi-transparent box = Entry Zone (61.8%–78.6% OTE)
— Gold semi-transparent box with "TARGET ZONE" = extension target (−50% to −61.8%)
— TP1–TP4 labels = structured take-profit levels
— Optional diagonal line = swing connection (low-to-high or high-to-low)
Suggested workflow:
— Zoom to the swing you want to analyze — the grid adapts automatically
— In a bullish trend: look for buy entries when price retraces into the Entry Zone (61.8%–78.6%), with stop loss below 100% (swing low), targeting TP1 (38.2%) → TP2 (0% / swing high) → TP3 (−27.2%) → TP4 (−61.8%)
— In a bearish trend: look for sell entries when price retraces up into the Entry Zone, stop above swing high, targeting downward extensions
— Use the dashboard to confirm trend direction and monitor whether price is currently in the Entry or Target zone
— Set alerts for zone touches to get notified when price reaches OTE or target levels without watching the chart
Customization tips:
— For a clean chart: enable only 0%, 61.8%, 78.6%, 100%, −27.2%, −61.8% — this gives you the OTE boundaries, swing anchors, and two extension targets
— For deep analysis: enable all 16 levels to see the full Fibonacci structure
— Adjust Label Offset to move level labels further right if your chart is crowded
— Toggle Show Diagonal Swing Line to visually confirm which high/low pair is being used
⚙️ KEY SETTINGS REFERENCE
— Show All Elements (default On): master toggle for all Fibonacci visuals
— Line Width (default 1): thickness of Fibonacci lines (1 = subtle, 5 = bold)
— Line Style (default Dashed): solid, dashed, or dotted
— Label Offset (default 17 bars): how far right of the last bar to place labels
— Individual Levels : 16 toggleable levels from 200% to −100%
— Show Entry Zone (default On): highlight the 61.8%–78.6% OTE box
— Show Target Zone (default On): highlight the −50% to −61.8% extension box
— Show Text in Zones (default On): display "ENTRY ZONE" / "TARGET ZONE" labels
— Show TP Labels (default On): display TP1–TP4 at key levels
— Show Level % Labels (default Off): display percentage text next to each line
📊 Dashboard
The info panel displays:
— Trend direction (Bullish / Bearish) based on swing sequence
— Signal status (Entry Zone / Target Zone / —) when price enters a key zone
— Swing range in price units
— Current timeframe and indicator version
🔔 Alerts
Two alert conditions (each fires once per zone entry on bar close):
— Entry Zone touch : price closes inside the 61.8%–78.6% retracement zone
— Target Zone touch : price closes inside the −50% to −61.8% extension zone
Both support standard text and JSON webhook format.
⚠️ IMPORTANT NOTES
— This indicator anchors to the visible chart range — it recalculates when you scroll or zoom. This is a feature, not a bug: it lets you analyze any swing by simply framing it on your screen. However, it means the grid will change if you move the chart.
— Fibonacci levels are not predictive — they are reference points based on the measured swing range. Price may or may not react at any given level.
— The Entry Zone (61.8%–78.6%) is derived from the OTE concept used in ICT/SMC methodology. It represents a high-probability retracement area, but no retracement zone guarantees a reversal.
— Zone alerts require bar-close confirmation and fire once per entry — they do not repeat while price remains in the zone.
— Works across all asset classes and timeframes. No volume data required.
Pine Script® インジケーター






















