📐 Indicator Cluster

Fibonacci Indicator Với AI — Auto Pine Script TradingView

Bởi Dan Machado · 10 phút đọc · Code ready

Fibonacci retracement là một trong những tools phổ biến nhất trong technical analysis. Thay vì draw manual mỗi lần, bạn có thể dùng AI để generate auto Fibonacci indicator — tự động detect swing high/low và plot levels. Tutorial này có code Pine Script v5 ready copy-paste.

Fibonacci Levels Là Gì?

Fibonacci retracement levels dựa trên dãy số Fibonacci. Các ratios quan trọng:

0%
Swing Point
23.6%
Shallow
38.2%
Moderate
50%
Mid
61.8%
Golden Ratio
78.6%
Deep
100%
Swing Point

⭐ Golden Ratio 61.8%

Level 61.8% (Golden Ratio) là quan trọng nhất. Price thường bounce hoặc reverse ở đây. Trong code dưới, chúng ta add alert đặc biệt khi price tiếp cận level này.

AI Prompt để Generate Indicator

📋 PROMPT

“Tạo Pine Script v5 indicator auto Fibonacci retracement. Tự động detect swing high và swing low trong lookback period (default 50 bars). Plot levels 0, 23.6, 38.2, 50, 61.8, 78.6, 100. Add dashboard table hiển thị price của mỗi level. Add alert khi price tiếp cận 61.8% golden ratio (within 0.5%). Overlay=true.”

Code Complete — Auto Fibonacci

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

// === INPUTS ===
lookback = input.int(50, "Swing Lookback Period", minval=10)
showLabels = input.bool(true, "Show Price Labels")
alertProximity = input.float(0.5, "Golden Ratio Alert Proximity %", step=0.1)

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

// === CALCULATE FIB LEVELS ===
fib_0    = swingLow
fib_236  = swingLow + fibRange * 0.236
fib_382  = swingLow + fibRange * 0.382
fib_500  = swingLow + fibRange * 0.500
fib_618  = swingLow + fibRange * 0.618
fib_786  = swingLow + fibRange * 0.786
fib_100  = swingHigh

// === PLOT LEVELS ===
plot(fib_0,   "0%",    color=color.new(color.gray, 30), linewidth=1)
plot(fib_236, "23.6%", color=color.new(#00E676, 30), linewidth=1)
plot(fib_382, "38.2%", color=color.new(#80E0A0, 30), linewidth=1)
plot(fib_500, "50%",   color=color.new(#FFC107, 0),  linewidth=2)
plot(fib_618, "61.8%", color=color.new(#FF9800, 0),  linewidth=2)
plot(fib_786, "78.6%", color=color.new(#FF5252, 30), linewidth=1)
plot(fib_100, "100%",  color=color.new(color.gray, 30), linewidth=1)

// === FILL ZONES ===
p618 = plot(fib_618, display=display.none)
p500 = plot(fib_500, display=display.none)
fill(p618, p500, color=color.new(#FFC107, 92), title="Golden Zone")

// === DASHBOARD TABLE ===
var table fibTable = table.new(position.top_right, 2, 8,
  bgcolor=color.new(color.black, 20),
  border_width=1, border_color=color.gray)

if barstate.islast and showLabels
    table.cell(fibTable, 0, 0, "FIB LEVEL", text_color=color.white,
      text_size=size.small, bgcolor=color.new(#FFC107, 30))
    table.cell(fibTable, 1, 0, "PRICE", text_color=color.white,
      text_size=size.small, bgcolor=color.new(#FFC107, 30))
    
    table.cell(fibTable, 0, 1, "0%", text_color=color.gray, text_size=size.tiny)
    table.cell(fibTable, 1, 1, str.tostring(fib_0, "#.#####"), text_color=color.gray, text_size=size.tiny)
    
    table.cell(fibTable, 0, 2, "23.6%", text_color=#00E676, text_size=size.tiny)
    table.cell(fibTable, 1, 2, str.tostring(fib_236, "#.#####"), text_color=#00E676, text_size=size.tiny)
    
    table.cell(fibTable, 0, 3, "38.2%", text_color=#80E0A0, text_size=size.tiny)
    table.cell(fibTable, 1, 3, str.tostring(fib_382, "#.#####"), text_color=#80E0A0, text_size=size.tiny)
    
    table.cell(fibTable, 0, 4, "50%", text_color=#FFC107, text_size=size.tiny)
    table.cell(fibTable, 1, 4, str.tostring(fib_500, "#.#####"), text_color=#FFC107, text_size=size.tiny)
    
    table.cell(fibTable, 0, 5, "61.8% ⭐", text_color=#FF9800, text_size=size.tiny)
    table.cell(fibTable, 1, 5, str.tostring(fib_618, "#.#####"), text_color=#FF9800, text_size=size.tiny)
    
    table.cell(fibTable, 0, 6, "78.6%", text_color=#FF5252, text_size=size.tiny)
    table.cell(fibTable, 1, 6, str.tostring(fib_786, "#.#####"), text_color=#FF5252, text_size=size.tiny)
    
    table.cell(fibTable, 0, 7, "100%", text_color=color.gray, text_size=size.tiny)
    table.cell(fibTable, 1, 7, str.tostring(fib_100, "#.#####"), text_color=color.gray, text_size=size.tiny)

// === GOLDEN RATIO ALERT ===
proximityDistance = fib_618 * alertProximity / 100
nearGoldenRatio = math.abs(close - fib_618) <= proximityDistance

plotshape(nearGoldenRatio, title="Near Golden Ratio",
  location=location.belowbar, color=#FF9800,
  style=shape.diamond, size=size.tiny)

alertcondition(nearGoldenRatio, title="Price Near 61.8% Golden Ratio",
  message="Price approaching Fibonacci 61.8% level — watch for reversal")

// === BREAKOUT ALERTS ===
alertcondition(ta.crossover(close, fib_618), title="Break Above 61.8%",
  message="Price broke above golden ratio — bullish continuation")
alertcondition(ta.crossunder(close, fib_618), title="Break Below 61.8%",
  message="Price broke below golden ratio — bearish continuation")

Cách Sử Dụng

  1. Mở TradingView, chọn asset (V75, EUR/USD)
  2. Click “Pine Editor” tab
  3. Paste code trên, save (Ctrl+S)
  4. Click “Add to chart”
  5. Indicator tự động plot Fib levels từ swing high/low recent
  6. Adjust “Swing Lookback Period” theo timeframe (50 cho M5, 100 cho H1)

Trading Strategy với Fibonacci

Strategy: Golden Ratio Bounce

  • Setup: Trong uptrend, đợi price retrace về 61.8%
  • Entry BUY: Price chạm 61.8% + RSI oversold (< 40)
  • Stop loss: Dưới 78.6% level
  • Take profit: Trở lại 23.6% hoặc 0% (swing high)
  • R:R: Thường 1:2 hoặc better

Strategy: Breakout Confirmation

  • Setup: Price consolidating quanh 50% level
  • Entry: Break above 61.8% với volume spike
  • Target: 100% level (swing high)
  • Invalidation: Close back below 50%

✓ Best Practices

1. Combine với trend. Fib retracement work tốt nhất trong trending markets, không sideways.
2. Confluence là key. Fib level + RSI + support/resistance = strong signal.
3. 61.8% và 50% là levels quan trọng nhất. 23.6% thường quá shallow.
4. Higher timeframe Fib stronger than lower. D1 Fib > M5 Fib.

Limitations

⚠️ Fibonacci Không Phải Magic

Fibonacci levels là self-fulfilling prophecy — work một phần vì nhiều traders watch chúng. Nhưng:
• Không guarantee bounce/reversal
• V75 (synthetic) ít respect Fib hơn forex/stocks
• Auto-detection swing có thể chọn sai swing points
• Best as confluence tool, không standalone

Customize với AI

Muốn modify indicator? Pakai follow-up prompts:

  • “Add Fibonacci extension levels (127.2%, 161.8%) cho take profit targets”
  • “Modify để chỉ plot Fib khi trend confirmed bằng EMA 50”
  • “Add multi-timeframe Fib — show H1 levels trên M5 chart”

Detail prompt engineering: 5 AI Prompts.

🚀 Test Fibonacci indicator trên Deriv V75 demo:

Mở Demo Deriv Miễn Phí

Bài Liên Quan

DM

Dan Machado

Founder IA Trader Pro · Fibonacci trader 5+ năm

⚠️ Disclaimer: Fibonacci levels không guarantee reversal. Backtest trước live. Deriv không được cấp phép bởi SBV. Bài viết này có chứa affiliate link Deriv. Disclaimer đầy đủ.