📐 Indicator Cluster

Fibonacci Indicator with AI — Auto Pine Script

By Dan Machado · 7 min read

Fibonacci retracement levels (23.6%, 38.2%, 50%, 61.8% golden, 78.6%) are some of the most-used support/resistance indicators in technical analysis. Drawing them manually is tedious. With AI-generated Pine Script, you can have them auto-plotted on any TradingView chart in seconds. This cluster gives you ready-to-use code.

🎯 What This Indicator Does

Automatically detects the highest high and lowest low over a configurable lookback period, then plots all 7 standard Fibonacci retracement levels with the 61.8% golden ratio emphasised. Works on V75, forex, JSE stocks, any timeframe.

The Math (5-Second Version)

Fibonacci levels are derived from the Fibonacci sequence (1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89…). Key ratios:

  • 61.8% (golden ratio): 21÷34 = 0.6176 — most respected level
  • 38.2%: 21÷55 = 0.3818
  • 23.6%: 21÷89 = 0.2360
  • 50%: not from Fibonacci but commonly used
  • 78.6%: √0.618 — deep retracement

Why traders care: prices frequently reverse at these levels (self-fulfilling because so many traders watch them).

Complete Pine Script v5 Code

Paste this into TradingView Pine Editor (free tier works):

▸ Pine Script v5 · Auto Fibonacci
//@version=5
indicator("Auto Fibonacci — IA Trader Pro", overlay=true)

// === INPUTS ===
lookback = input.int(50, "Lookback Period", minval=10)
showLabels = input.bool(true, "Show Level Labels")
extendRight = input.bool(true, "Extend Lines Right")

// === DETECT SWING HIGH/LOW ===
swingHigh = ta.highest(high, lookback)
swingLow = ta.lowest(low, lookback)
range_ = swingHigh - swingLow

// === FIB LEVELS ===
fib_236 = swingHigh - range_ * 0.236
fib_382 = swingHigh - range_ * 0.382
fib_500 = swingHigh - range_ * 0.500
fib_618 = swingHigh - range_ * 0.618
fib_786 = swingHigh - range_ * 0.786

// === PLOT LINES ===
ext = extendRight ? extend.right : extend.none
line.new(bar_index[lookback], swingHigh, bar_index, swingHigh,
  color=#FF5252, width=1, extend=ext)
line.new(bar_index[lookback], fib_236, bar_index, fib_236,
  color=#FFA000, width=1, extend=ext)
line.new(bar_index[lookback], fib_382, bar_index, fib_382,
  color=#FFC107, width=1, extend=ext)
line.new(bar_index[lookback], fib_500, bar_index, fib_500,
  color=#00BCD4, width=1, style=line.style_dashed, extend=ext)
// GOLDEN 61.8% — EMPHASISED
line.new(bar_index[lookback], fib_618, bar_index, fib_618,
  color=#00E676, width=2, extend=ext)
line.new(bar_index[lookback], fib_786, bar_index, fib_786,
  color=#9C27B0, width=1, extend=ext)
line.new(bar_index[lookback], swingLow, bar_index, swingLow,
  color=#448AFF, width=1, extend=ext)

// === LABELS ===
if showLabels and barstate.islast
    label.new(bar_index, swingHigh, "100% (High)", color=color.new(#FF5252, 70),
      textcolor=color.white, style=label.style_label_left, size=size.tiny)
    label.new(bar_index, fib_618, "★ 61.8% Golden", color=color.new(#00E676, 70),
      textcolor=color.white, style=label.style_label_left, size=size.tiny)
    label.new(bar_index, swingLow, "0% (Low)", color=color.new(#448AFF, 70),
      textcolor=color.white, style=label.style_label_left, size=size.tiny)

// === ALERTS ===
goldenTouch = math.abs(close - fib_618) / fib_618 < 0.001
alertcondition(goldenTouch, "Golden 618 Touch",
  "Price at 61.8% Fibonacci level on {{ticker}}")

How to Use Effectively

  1. Apply on strong trend: Fibonacci works best when there’s a clear directional move
  2. Wait for 61.8% pullback: highest probability reversal level
  3. Confirm with another indicator: RSI oversold/overbought at fib level = stronger signal
  4. Set stops beyond next level: if entering at 61.8%, stop below 78.6%
  5. Take profit at previous swing: 0% or 100% level

Customisation Prompts for AI

Ask Claude or ChatGPT to modify the code:

  • “Add Fibonacci extensions (1.272, 1.618, 2.618) for take-profit levels”
  • “Make lines fade after price moves 5% away from level”
  • “Detect when price rejects 61.8% and plot reversal arrows”
  • “Convert to strategy script with auto-entry at 61.8% + 1% stop loss”

Fibonacci on V75 (SA Context)

📊 V75 Performance

Fibonacci works decently on V75 because synthetic indices have mean-reverting characteristics. The 61.8% golden level acts as support/resistance roughly 62% of the time in our testing — better than random (50%) but not a holy grail. Combine with RSI for higher conviction signals.

Common Mistakes

  • Drawing Fib on weak trends — needs strong directional move first
  • Using only Fib as entry — combine with at least one momentum indicator
  • Tight stops below 61.8% — price often briefly violates before reversing
  • Wrong direction: uptrend = drag from low to high, downtrend = high to low

🚀 Test this Fib indicator on Deriv demo with V75:

Open Free Demo Account →

Related Reading

DM

Dan Machado

Founder IA Trader Pro · Daily Pine Script user

⚠️ Disclaimer: Fibonacci levels are not guaranteed reversal zones. Always backtest and use risk management. Deriv is FSCA-authorised (FSP 50885). Contains affiliate links. Full disclaimer.