ChatGPT & Claude cho Trading Indicators 2026 — 5 Pine Scripts Ready
Năm 2026, bạn không cần là Pine Script developer để có custom indicators. ChatGPT và Claude tạo code production-quality trong vài phút. Tutorial này có 5 Pine Scripts complete đã được tạo bởi AI, tested trên TradingView, ready copy-paste vào chart của bạn.
ChatGPT vs Claude — Cái Nào Tốt Hơn?
🟢 ChatGPT (GPT-4/5)
- Pine Script syntax accuracy cao
- Faster response time
- Better cho simple indicators
- Free tier đủ cho casual use
- Plugins ecosystem rộng
- Excellent cho RSI, MACD, basics
🟠 Claude (Sonnet/Opus)
- Context window lớn hơn (200K+ tokens)
- Code reasoning sâu hơn
- Better cho complex multi-indicator
- Less hallucination về syntax
- Better explanation logic
- Excellent cho debugging existing code
💡 Best Practice
Sử dụng cả 2. ChatGPT cho first draft (faster), Claude cho debugging và optimization (deeper reasoning). Cross-check outputs để identify errors. Both free tiers đủ cho hầu hết tasks.
Anatomy của Pine Script v5
Trước khi prompt AI, hiểu structure cơ bản:
//@version=5
indicator("My Indicator", overlay=true)
// === INPUTS ===
length = input.int(14, "Period")
source = input.source(close, "Source")
// === CALCULATIONS ===
ma = ta.sma(source, length)
// === PLOTS ===
plot(ma, "MA", color=color.blue, linewidth=2)
// === ALERTS ===
alertcondition(ta.crossover(close, ma), title="Buy", message="Cross above MA")
Khi prompt AI, mention “Pine Script v5” để tránh code v4 outdated.
Indicator #1: RSI với Arrows trên Chart
//@version=5
indicator("RSI Arrows — IA Trader Pro", overlay=true)
// === INPUTS ===
rsiLen = input.int(14, "RSI Length")
osLevel = input.int(30, "Oversold Level")
obLevel = input.int(70, "Overbought Level")
// === CALCULATIONS ===
rsi = ta.rsi(close, rsiLen)
// === SIGNALS ===
oversold = rsi < osLevel and rsi[1] >= osLevel
overbought = rsi > obLevel and rsi[1] <= obLevel
// === PLOT ARROWS ===
plotshape(oversold, title="Oversold",
location=location.belowbar,
color=color.new(#00E676, 0),
style=shape.triangleup,
size=size.small,
text="RSI " + str.tostring(math.round(rsi)),
textcolor=color.white)
plotshape(overbought, title="Overbought",
location=location.abovebar,
color=color.new(#FF5252, 0),
style=shape.triangledown,
size=size.small,
text="RSI " + str.tostring(math.round(rsi)),
textcolor=color.white)
// === BACKGROUND ===
bgcolor(rsi < osLevel ? color.new(#00E676, 95) : na)
bgcolor(rsi > obLevel ? color.new(#FF5252, 95) : na)
// === ALERTS ===
alertcondition(oversold, title="RSI Oversold",
message="RSI dropped below 30 — potential buy signal")
alertcondition(overbought, title="RSI Overbought",
message="RSI rose above 70 — potential sell signal")
Indicator #2: MACD Histogram Custom
//@version=5
indicator("MACD Histogram Custom — IA Trader Pro")
// === INPUTS ===
fastLen = input.int(12, "Fast Length")
slowLen = input.int(26, "Slow Length")
sigLen = input.int(9, "Signal Length")
// === CALCULATIONS ===
[macdLine, signalLine, histLine] = ta.macd(close, fastLen, slowLen, sigLen)
// === COLOR LOGIC ===
histColor = histLine > 0 ?
(histLine > histLine[1] ? color.new(#00E676, 0) : color.new(#00E676, 50)) :
(histLine < histLine[1] ? color.new(#FF5252, 0) : color.new(#FF5252, 50))
// === PLOTS ===
plot(histLine, "Histogram", color=histColor, style=plot.style_columns, linewidth=4)
plot(macdLine, "MACD", color=#448AFF, linewidth=2)
plot(signalLine, "Signal", color=#FFC107, linewidth=2)
hline(0, "Zero", color=color.gray, linestyle=hline.style_dashed)
// === DIVERGENCE DETECTION (basic) ===
bullDiv = ta.lowest(low, 14) == low and ta.lowest(macdLine, 14) != macdLine
bearDiv = ta.highest(high, 14) == high and ta.highest(macdLine, 14) != macdLine
plotshape(bullDiv, title="Bullish Divergence",
location=location.bottom, color=#00E676, style=shape.labelup,
text="BULL DIV", textcolor=color.white, size=size.tiny)
plotshape(bearDiv, title="Bearish Divergence",
location=location.top, color=#FF5252, style=shape.labeldown,
text="BEAR DIV", textcolor=color.white, size=size.tiny)
// === ALERTS ===
alertcondition(ta.crossover(macdLine, 0), title="MACD Cross Above Zero",
message="Bullish momentum confirmed")
alertcondition(ta.crossunder(macdLine, 0), title="MACD Cross Below Zero",
message="Bearish momentum confirmed")
alertcondition(bullDiv, title="Bullish Divergence",
message="Potential reversal upward")
alertcondition(bearDiv, title="Bearish Divergence",
message="Potential reversal downward")
Indicator #3: Bollinger Bands + RSI Combo
//@version=5
indicator("BB + RSI Combo — IA Trader Pro", overlay=true)
// === INPUTS ===
bbLen = input.int(20, "BB Length")
bbMult = input.float(2.0, "BB StdDev", step=0.1)
rsiLen = input.int(14, "RSI Length")
rsiOs = input.int(30, "RSI Oversold")
rsiOb = input.int(70, "RSI Overbought")
// === BB CALCULATIONS ===
basis = ta.sma(close, bbLen)
dev = bbMult * ta.stdev(close, bbLen)
upperBB = basis + dev
lowerBB = basis - dev
// === RSI CALCULATIONS ===
rsi = ta.rsi(close, rsiLen)
// === SIGNALS (DUAL CONFIRMATION) ===
buySignal = ta.crossunder(low, lowerBB) and rsi < rsiOs
sellSignal = ta.crossover(high, upperBB) and rsi > rsiOb
// === PLOT BB ===
plot(basis, "Middle", color=color.orange, linewidth=1)
p1 = plot(upperBB, "Upper", color=color.new(#FF5252, 60))
p2 = plot(lowerBB, "Lower", color=color.new(#00E676, 60))
fill(p1, p2, color=color.new(color.blue, 95))
// === PLOT SIGNALS ===
plotshape(buySignal, title="BUY",
location=location.belowbar,
color=color.new(#00E676, 0),
style=shape.triangleup,
size=size.normal,
text="BUY",
textcolor=color.white)
plotshape(sellSignal, title="SELL",
location=location.abovebar,
color=color.new(#FF5252, 0),
style=shape.triangledown,
size=size.normal,
text="SELL",
textcolor=color.white)
// === BACKGROUND HIGHLIGHT ===
bgcolor(buySignal ? color.new(#00E676, 85) : na)
bgcolor(sellSignal ? color.new(#FF5252, 85) : na)
// === ALERTS ===
alertcondition(buySignal, title="BB+RSI Buy",
message="Strong BUY: Price below lower BB + RSI oversold")
alertcondition(sellSignal, title="BB+RSI Sell",
message="Strong SELL: Price above upper BB + RSI overbought")
Indicator #4: Volume Filter Strategy
//@version=5
indicator("EMA Cross + Volume Filter — IA Trader Pro", overlay=true)
// === INPUTS ===
fastLen = input.int(9, "EMA Fast")
slowLen = input.int(21, "EMA Slow")
volLen = input.int(20, "Volume MA Length")
volMult = input.float(1.5, "Volume Spike Multiplier", step=0.1)
// === CALCULATIONS ===
emaFast = ta.ema(close, fastLen)
emaSlow = ta.ema(close, slowLen)
volMa = ta.sma(volume, volLen)
volSpike = volume > volMa * volMult
// === SIGNALS ===
bullCross = ta.crossover(emaFast, emaSlow) and volSpike
bearCross = ta.crossunder(emaFast, emaSlow) and volSpike
// === TRACKING ===
var int totalSignals = 0
var int wins = 0
var float estimatedPnL = 0.0
if bullCross
totalSignals := totalSignals + 1
if bearCross
totalSignals := totalSignals + 1
// Simulate: if next candle moves favorably, count win
if bullCross[1] and close > close[1]
wins := wins + 1
estimatedPnL := estimatedPnL + (close - close[1])
if bearCross[1] and close < close[1]
wins := wins + 1
estimatedPnL := estimatedPnL + (close[1] - close)
// === PLOTS ===
plot(emaFast, "EMA Fast", color=#00E676, linewidth=2)
plot(emaSlow, "EMA Slow", color=#FF5252, linewidth=2)
plotshape(bullCross, title="BUY", location=location.belowbar,
color=#00E676, style=shape.triangleup, size=size.small, text="BUY+V",
textcolor=color.white)
plotshape(bearCross, title="SELL", location=location.abovebar,
color=#FF5252, style=shape.triangledown, size=size.small, text="SELL+V",
textcolor=color.white)
// === METRICS DASHBOARD ===
var table metrics = table.new(position.top_right, 2, 4,
bgcolor=color.new(color.black, 20),
border_width=1, border_color=color.gray)
if barstate.islast
winRate = totalSignals > 0 ? wins / totalSignals * 100 : 0
table.cell(metrics, 0, 0, "METRIC", text_color=color.white, text_size=size.small,
bgcolor=color.new(#448AFF, 30))
table.cell(metrics, 1, 0, "VALUE", text_color=color.white, text_size=size.small,
bgcolor=color.new(#448AFF, 30))
table.cell(metrics, 0, 1, "Signals", text_color=color.white, text_size=size.tiny)
table.cell(metrics, 1, 1, str.tostring(totalSignals), text_color=color.white, text_size=size.tiny)
table.cell(metrics, 0, 2, "Wins", text_color=color.white, text_size=size.tiny)
table.cell(metrics, 1, 2, str.tostring(wins), text_color=#00E676, text_size=size.tiny)
table.cell(metrics, 0, 3, "Win Rate", text_color=color.white, text_size=size.tiny)
table.cell(metrics, 1, 3, str.tostring(winRate, "#.0") + "%",
text_color=winRate > 60 ? #00E676 : #FF5252, text_size=size.tiny)
Indicator #5: Multi-Indicator Dashboard
//@version=5
indicator("Multi-Indicator Dashboard — IA Trader Pro", overlay=true)
// === CALCULATIONS ===
rsi = ta.rsi(close, 14)
[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)
ema9 = ta.ema(close, 9)
ema21 = ta.ema(close, 21)
basis = ta.sma(close, 20)
dev = 2.0 * ta.stdev(close, 20)
upperBB = basis + dev
lowerBB = basis - dev
k = ta.sma(ta.stoch(close, high, low, 14), 3)
d = ta.sma(k, 3)
volMa = ta.sma(volume, 20)
// === STATUS LOGIC ===
rsiStatus = rsi < 30 ? "OVERSOLD" : rsi > 70 ? "OVERBOUGHT" : rsi > 50 ? "BULL" : "BEAR"
rsiColor = rsi < 30 ? #00E676 : rsi > 70 ? #FF5252 : rsi > 50 ? #80E0A0 : #FFA080
macdStatus = histLine > 0 ? "BULL" : "BEAR"
macdColor = histLine > 0 ? #00E676 : #FF5252
emaStatus = ema9 > ema21 ? "BULL" : "BEAR"
emaColor = ema9 > ema21 ? #00E676 : #FF5252
bbStatus = close > upperBB ? "OVERBOUGHT" : close < lowerBB ? "OVERSOLD" :
close > basis ? "BULL" : "BEAR"
bbColor = close > upperBB ? #FF5252 : close < lowerBB ? #00E676 :
close > basis ? #80E0A0 : #FFA080
stochStatus = k < 20 ? "OVERSOLD" : k > 80 ? "OVERBOUGHT" : k > d ? "BULL" : "BEAR"
stochColor = k < 20 ? #00E676 : k > 80 ? #FF5252 : k > d ? #80E0A0 : #FFA080
volStatus = volume > volMa * 1.5 ? "SPIKE" : "NORMAL"
volColor = volume > volMa * 1.5 ? #FFC107 : color.gray
// === COUNT BULLISH ===
bullCount = (rsi > 50 ? 1 : 0) + (histLine > 0 ? 1 : 0) + (ema9 > ema21 ? 1 : 0) +
(close > basis ? 1 : 0) + (k > d ? 1 : 0)
overallStatus = bullCount >= 4 ? "🚀 STRONG BUY" :
bullCount == 3 ? "↗ BUY" :
bullCount == 2 ? "→ NEUTRAL" :
bullCount == 1 ? "↘ SELL" : "🛑 STRONG SELL"
overallColor = bullCount >= 4 ? #00E676 :
bullCount == 3 ? #80E0A0 :
bullCount == 2 ? color.gray :
bullCount == 1 ? #FFA080 : #FF5252
// === DASHBOARD TABLE ===
var table dash = table.new(position.top_right, 2, 8,
bgcolor=color.new(color.black, 20),
border_width=1, border_color=color.gray)
if barstate.islast
table.cell(dash, 0, 0, "INDICATOR", text_color=color.white, text_size=size.small,
bgcolor=color.new(#448AFF, 30))
table.cell(dash, 1, 0, "STATUS", text_color=color.white, text_size=size.small,
bgcolor=color.new(#448AFF, 30))
table.cell(dash, 0, 1, "RSI " + str.tostring(rsi, "#"), text_color=color.white, text_size=size.tiny)
table.cell(dash, 1, 1, rsiStatus, text_color=rsiColor, text_size=size.tiny)
table.cell(dash, 0, 2, "MACD", text_color=color.white, text_size=size.tiny)
table.cell(dash, 1, 2, macdStatus, text_color=macdColor, text_size=size.tiny)
table.cell(dash, 0, 3, "EMA 9/21", text_color=color.white, text_size=size.tiny)
table.cell(dash, 1, 3, emaStatus, text_color=emaColor, text_size=size.tiny)
table.cell(dash, 0, 4, "Bollinger", text_color=color.white, text_size=size.tiny)
table.cell(dash, 1, 4, bbStatus, text_color=bbColor, text_size=size.tiny)
table.cell(dash, 0, 5, "Stoch K/D", text_color=color.white, text_size=size.tiny)
table.cell(dash, 1, 5, stochStatus, text_color=stochColor, text_size=size.tiny)
table.cell(dash, 0, 6, "Volume", text_color=color.white, text_size=size.tiny)
table.cell(dash, 1, 6, volStatus, text_color=volColor, text_size=size.tiny)
table.cell(dash, 0, 7, "OVERALL", text_color=color.white, text_size=size.tiny,
bgcolor=color.new(#FFC107, 60))
table.cell(dash, 1, 7, overallStatus, text_color=overallColor, text_size=size.tiny,
bgcolor=color.new(#FFC107, 80))
Cách Install & Test
- Truy cập tradingview.com
- Chọn chart asset (V75, EUR/USD, BTC)
- Click “Pine Editor” tab ở bottom
- Copy code indicator, paste vào editor
- Save (Ctrl+S), đặt tên
- Click “Add to chart”
- Test trên historical data trước
- Setup alerts nếu muốn notifications
Prompt Engineering Tips
✓ Best Practices Khi Prompt AI
1. Specify “Pine Script v5”. Tránh code v4 outdated.
2. Be specific về parameters. “Length 14, Source close”.
3. Mention overlay or panel. overlay=true cho price chart, false cho separate.
4. Request alerts explicitly. AI often forgets này.
5. Ask for dashboard/table. Visual stats helpful.
6. Test edge cases: “What happens khi không có data?”.
7. Iterate. First version rarely perfect — refine.
Common AI Errors & Fixes
Lỗi: “ta.rsi” Not Recognized
AI sometimes use Pine Script v4 syntax (rsi() instead of ta.rsi()). Fix: explicitly request v5.
Lỗi: Plot Returns “na”
Calculation occurs before enough data. Add `na()` checks hoặc use `ta.barssince()` để delay plot.
Lỗi: Alert không trigger
`alertcondition()` chỉ activate khi user create alert in TradingView. Request “alert when condition true” explicitly.
Lỗi: Table không hiển thị
Table cells phải được populate inside `if barstate.islast` block. Otherwise nothing displays.
Mở Rộng Tutorial Này
- 5 AI Prompts Trader Cần Biết
- 10 Pine Scripts Ready Library
- Auto Fibonacci với AI
- SuperTrend + MACD Combo
- Ichimoku Cloud Custom
🚀 Test 5 Pine Scripts trên Deriv V75 demo (24/7 chart, miễn phí):
Mở Demo Deriv Miễn Phí