Pine Script 範例庫
直接複製貼上的 TradingView Pine Script + TVSBot 配置。先到 TV 把 Pine 貼進去 → 設 Alert → 把 Message body 換成下方 JSON(記得改 webhook_secret 跟交易所)→ Webhook URL 從 dashboard 主頁複製。
- 每個範本都有適用 / 不適用市場類型,看清楚再用
- 務必先 Dry-run 跑一兩週看訊號品質再切實單
- 建議設「每日下單上限」防止異常市況連續觸發
RSI 均值回歸
經典的「超賣買進 / 超賣賣出」邏輯。RSI 跌破 30 視為超賣準備反彈 → buy;漲破 70 視為超買準備回落 → sell。震盪盤效果好,趨勢盤會連續挨刀。
//@version=5
strategy("TVSBot RSI Mean Reversion", overlay=true)
// 參數
rsiLength = input.int(14, "RSI 週期")
oversold = input.int(30, "超賣閾值")
overbought = input.int(70, "超買閾值")
// 計算 RSI
rsi = ta.rsi(close, rsiLength)
// 條件
longCondition = ta.crossover(rsi, oversold)
shortCondition = ta.crossunder(rsi, overbought)
// 進出場(每個 alert 觸發都帶 strategy.order.action)
if longCondition
strategy.entry("Long", strategy.long, alert_message='{"side":"buy"}')
if shortCondition
strategy.entry("Short", strategy.short, alert_message='{"side":"sell"}')
// 視覺輔助
plot(rsi, "RSI", color=color.blue)
hline(oversold, "Oversold", color=color.green)
hline(overbought, "Overbought", color=color.red){
"secret": "<你的 webhook_secret>",
"strategy": "rsi-mean-reversion",
"side": "{{strategy.order.action}}",
"symbol": "BTCUSDT",
"exchange": "binance",
"market_type": "spot",
"qty_type": "percent",
"qty": 10,
"tp_pct": 3,
"sl_pct": 2
}ⓘ 記得改 secret(你的 webhook_secret,從策略 TV 模板按鈕拿),以及 exchange 跟 symbol(你綁定的交易所)
EMA 黃金/死亡交叉
短期 EMA 上穿長期 EMA = 黃金交叉做多;下穿 = 死亡交叉做空。趨勢追蹤經典款,缺點是震盪盤會被「假突破」連續打臉。建議用較長週期(如 4h / 1d)+ 止損。
//@version=5
strategy("TVSBot EMA Cross", overlay=true)
fastLen = input.int(12, "短期 EMA")
slowLen = input.int(26, "長期 EMA")
fastEMA = ta.ema(close, fastLen)
slowEMA = ta.ema(close, slowLen)
longCondition = ta.crossover(fastEMA, slowEMA)
shortCondition = ta.crossunder(fastEMA, slowEMA)
if longCondition
strategy.entry("Long", strategy.long, alert_message='{"side":"buy"}')
if shortCondition
strategy.entry("Short", strategy.short, alert_message='{"side":"sell"}')
plot(fastEMA, "Fast EMA", color=color.orange)
plot(slowEMA, "Slow EMA", color=color.blue){
"secret": "<你的 webhook_secret>",
"strategy": "ema-crossover",
"side": "{{strategy.order.action}}",
"symbol": "BTCUSDT",
"exchange": "binance",
"market_type": "futures",
"margin_pct": 10,
"leverage": 3,
"tp_pct": 5,
"sl_pct": 3
}ⓘ 記得改 secret(你的 webhook_secret,從策略 TV 模板按鈕拿),以及 exchange 跟 symbol(你綁定的交易所)
布林帶觸碰回彈
價格觸碰布林帶下軌且 RSI 仍 < 50 視為超賣 → buy;觸碰上軌且 RSI > 50 → sell。比純 RSI 更嚴格(要兩個條件同時成立)。
//@version=5
strategy("TVSBot Bollinger Bounce", overlay=true)
bbLen = input.int(20, "BB 週期")
bbStd = input.float(2.0, "BB 標準差")
rsiLen = input.int(14, "RSI 週期")
basis = ta.sma(close, bbLen)
dev = bbStd * ta.stdev(close, bbLen)
upper = basis + dev
lower = basis - dev
rsi = ta.rsi(close, rsiLen)
longCondition = close <= lower and rsi < 50
shortCondition = close >= upper and rsi > 50
if longCondition
strategy.entry("Long", strategy.long, alert_message='{"side":"buy"}')
if shortCondition
strategy.entry("Short", strategy.short, alert_message='{"side":"sell"}')
plot(basis, "BB Mid")
plot(upper, "BB Upper", color=color.red)
plot(lower, "BB Lower", color=color.green){
"secret": "<你的 webhook_secret>",
"strategy": "bollinger-bounce",
"side": "{{strategy.order.action}}",
"symbol": "BTCUSDT",
"exchange": "binance",
"market_type": "spot",
"qty_type": "percent",
"qty": 8,
"tp_pct": 4,
"sl_pct": 1.5
}ⓘ 記得改 secret(你的 webhook_secret,從策略 TV 模板按鈕拿),以及 exchange 跟 symbol(你綁定的交易所)
SuperTrend 趨勢跟蹤
SuperTrend 翻多 → buy;翻空 → sell。比 EMA cross 反應更快,止損也內建(基於 ATR)。趨勢盤的主力選手。
//@version=5
strategy("TVSBot SuperTrend", overlay=true)
atrPeriod = input.int(10, "ATR 週期")
factor = input.float(3.0, "SuperTrend 倍數")
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
longCondition = ta.change(direction) < 0 // 從空翻多
shortCondition = ta.change(direction) > 0 // 從多翻空
if longCondition
strategy.entry("Long", strategy.long, alert_message='{"side":"buy"}')
if shortCondition
strategy.entry("Short", strategy.short, alert_message='{"side":"sell"}')
plot(direction < 0 ? supertrend : na, "Up", color=color.green, linewidth=2)
plot(direction > 0 ? supertrend : na, "Down", color=color.red, linewidth=2){
"secret": "<你的 webhook_secret>",
"strategy": "supertrend",
"side": "{{strategy.order.action}}",
"symbol": "BTCUSDT",
"exchange": "binance",
"market_type": "futures",
"margin_pct": 15,
"leverage": 5,
"tp_pct": 8,
"sl_pct": 4
}ⓘ 記得改 secret(你的 webhook_secret,從策略 TV 模板按鈕拿),以及 exchange 跟 symbol(你綁定的交易所)
成交量突破
收盤價突破 N 根 K 的最高點 + 成交量 > 平均成交量 1.5 倍 → buy;跌破最低點 + 量爆 → sell。捕捉大行情的進場時機。
//@version=5
strategy("TVSBot Volume Breakout", overlay=true)
lookback = input.int(20, "突破回看 K 數")
volMult = input.float(1.5, "成交量倍數")
highestHigh = ta.highest(high, lookback)[1]
lowestLow = ta.lowest(low, lookback)[1]
avgVol = ta.sma(volume, lookback)
longCondition = ta.crossover(close, highestHigh) and volume > avgVol * volMult
shortCondition = ta.crossunder(close, lowestLow) and volume > avgVol * volMult
if longCondition
strategy.entry("Long", strategy.long, alert_message='{"side":"buy"}')
if shortCondition
strategy.entry("Short", strategy.short, alert_message='{"side":"sell"}')
plot(highestHigh, "Lookback High", color=color.red)
plot(lowestLow, "Lookback Low", color=color.green){
"secret": "<你的 webhook_secret>",
"strategy": "volume-breakout",
"side": "{{strategy.order.action}}",
"symbol": "BTCUSDT",
"exchange": "binance",
"market_type": "futures",
"margin_pct": 8,
"leverage": 3,
"tp_pct": 10,
"sl_pct": 3
}ⓘ 記得改 secret(你的 webhook_secret,從策略 TV 模板按鈕拿),以及 exchange 跟 symbol(你綁定的交易所)
DCA 階梯式進場(被動定投)
每跌 N% 自動加倉。不做空、不停損 — 純 averaging down 平攤成本。適合長期看好但短線怕抓底失敗的用戶。**用 margin / leverage 跑這個會 100% 爆倉,請只用現貨。**
//@version=5
strategy("TVSBot DCA Step", overlay=true)
stepPct = input.float(5.0, "每跌 N% 加倉一次")
maxBuys = input.int(10, "最多加倉次數")
var float lastBuyPrice = na
var int buyCount = 0
// 第一次進場:直接 buy
if na(lastBuyPrice) and buyCount < maxBuys
strategy.entry("DCA-1", strategy.long, alert_message='{"side":"buy"}')
lastBuyPrice := close
buyCount += 1
// 後續 N% 跌幅就再加一次
priceDropPct = (lastBuyPrice - close) / lastBuyPrice * 100
if not na(lastBuyPrice) and priceDropPct >= stepPct and buyCount < maxBuys
strategy.entry("DCA-" + str.tostring(buyCount + 1), strategy.long, alert_message='{"side":"buy"}')
lastBuyPrice := close
buyCount += 1
plot(lastBuyPrice, "Last Buy", color=color.orange, style=plot.style_circles){
"secret": "<你的 webhook_secret>",
"strategy": "dca-grid",
"side": "buy",
"symbol": "BTCUSDT",
"exchange": "binance",
"market_type": "spot",
"qty_type": "usdt",
"qty": 100
}ⓘ 記得改 secret(你的 webhook_secret,從策略 TV 模板按鈕拿),以及 exchange 跟 symbol(你綁定的交易所)