πŸ“Š Ready Indicator

Automatic Fibonacci Indicator with AI β€” Ready Code for TradingView

By PrimeTraderAI Team Β· May 2026 Β· 10 min

Fibonacci retracement is one of the most-used tools by professional traders. The problem? Drawing it manually on every asset is tedious. The solution: an indicator that detects the pivots automatically and draws the levels for you.

In this post, I’ll hand you the ready Pine Script v5 code, AI-generated, that does exactly that β€” and explain how to customize it.

What the indicator does

  • Automatically detects the latest swing high and swing low
  • Draws the 7 Fibonacci levels: 0%, 23.6%, 38.2%, 50%, 61.8%, 78.6%, 100%
  • Each level with a different color and a label showing the exact value
  • Highlights the most important levels (38.2%, 50%, 61.8%) with thicker lines
  • Alerts when price touches the 61.8% level (classic reversal zone)
  • 100% configurable parameters

Complete Code

Pine Script v5πŸ“‹ Copy
//@version=5
indicator("Fibonacci Auto β€” IA Trader Pro", overlay=true, max_lines_count=20, max_labels_count=20)

// === PARAMETERS ===
lookback = input.int(50, "Lookback (candles)", minval=10)
showLabels = input.bool(true, "Show labels")
alertOn618 = input.bool(true, "Alert on 61.8%")

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

// === CALCULATE FIBONACCI LEVELS ===
fib0    = swingLow
fib236  = swingLow + range_ * 0.236
fib382  = swingLow + range_ * 0.382
fib500  = swingLow + range_ * 0.500
fib618  = swingLow + range_ * 0.618
fib786  = swingLow + range_ * 0.786
fib100  = swingHigh

// === DRAW LINES ===
var line l0   = na
var line l236 = na
var line l382 = na
var line l500 = na
var line l618 = na
var line l786 = na
var line l100 = na

if barstate.islast
    line.delete(l0)
    line.delete(l236)
    line.delete(l382)
    line.delete(l500)
    line.delete(l618)
    line.delete(l786)
    line.delete(l100)

    l0   := line.new(bar_index - lookback, fib0,   bar_index, fib0,   color=color.gray,   width=1, extend=extend.right)
    l236 := line.new(bar_index - lookback, fib236, bar_index, fib236, color=#FF9800,      width=1, extend=extend.right)
    l382 := line.new(bar_index - lookback, fib382, bar_index, fib382, color=#b8893d,      width=2, extend=extend.right)
    l500 := line.new(bar_index - lookback, fib500, bar_index, fib500, color=#448AFF,      width=2, extend=extend.right, style=line.style_dashed)
    l618 := line.new(bar_index - lookback, fib618, bar_index, fib618, color=#dc2626,      width=3, extend=extend.right)
    l786 := line.new(bar_index - lookback, fib786, bar_index, fib786, color=#E040FB,      width=1, extend=extend.right)
    l100 := line.new(bar_index - lookback, fib100, bar_index, fib100, color=color.gray,   width=1, extend=extend.right)

// === LABELS ===
var label lb0   = na
var label lb236 = na
var label lb382 = na
var label lb500 = na
var label lb618 = na
var label lb786 = na
var label lb100 = na

if barstate.islast and showLabels
    label.delete(lb0)
    label.delete(lb236)
    label.delete(lb382)
    label.delete(lb500)
    label.delete(lb618)
    label.delete(lb786)
    label.delete(lb100)

    lb0   := label.new(bar_index + 5, fib0,   "0% (" + str.tostring(fib0, "#.####") + ")",   color=color.new(color.gray, 70),   textcolor=color.gray,   style=label.style_label_left, size=size.small)
    lb236 := label.new(bar_index + 5, fib236, "23.6% (" + str.tostring(fib236, "#.####") + ")", color=color.new(#FF9800, 70),      textcolor=#FF9800,      style=label.style_label_left, size=size.small)
    lb382 := label.new(bar_index + 5, fib382, "38.2% (" + str.tostring(fib382, "#.####") + ")", color=color.new(#b8893d, 70),      textcolor=#b8893d,      style=label.style_label_left, size=size.small)
    lb500 := label.new(bar_index + 5, fib500, "50% (" + str.tostring(fib500, "#.####") + ")",   color=color.new(#448AFF, 70),      textcolor=#448AFF,      style=label.style_label_left, size=size.small)
    lb618 := label.new(bar_index + 5, fib618, "61.8% (" + str.tostring(fib618, "#.####") + ")", color=color.new(#dc2626, 70),      textcolor=#dc2626,      style=label.style_label_left, size=size.small)
    lb786 := label.new(bar_index + 5, fib786, "78.6% (" + str.tostring(fib786, "#.####") + ")", color=color.new(#E040FB, 70),      textcolor=#E040FB,      style=label.style_label_left, size=size.small)
    lb100 := label.new(bar_index + 5, fib100, "100% (" + str.tostring(fib100, "#.####") + ")", color=color.new(color.gray, 70),   textcolor=color.gray,   style=label.style_label_left, size=size.small)

// === ALERTS ===
touch618 = math.abs(close - fib618) < (range_ * 0.005)
alertcondition(alertOn618 and touch618, "Fib 61.8%", "Price touched the 61.8% level β€” possible reversal")

How to use

  1. Open TradingView β†’ any chart (e.g., EUR/USD, Volatility 75)
  2. Click Pine Editor at the bottom
  3. Delete the default code and paste the code above
  4. Click Add to chart
  5. Fibonacci levels appear automatically on the chart

Customize with AI

Want to adapt the indicator? Ask AI (ChatGPT or Claude) to modify it. Examples:

  • “Change the lookback to 100 candles and add the 127.2% extension level”
  • “Add buy arrows when price touches 61.8% in an uptrend”
  • “Paint the chart background green when price is between 38.2% and 61.8%”
  • “Convert this into a strategy with backtest”

πŸ’‘ Tip

Fibonacci works best in markets with clear trend. In sideways markets, levels lose meaning. Combine with other indicators (EMA, RSI) to confirm entries.

πŸš€ Test the indicator on TradingView and apply it on Deriv (free demo account):

Open Deriv Demo Account β†’
DM

PrimeTraderAI Team

Library at Indicators & Scripts.

⚠️ Educational indicator. Trading involves risk. Disclaimer.

Similar Posts