← 回文件首頁

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。震盪盤效果好,趨勢盤會連續挨刀。

✓ 適合
震盪盤、區間整理時段的現貨
✗ 不適合
單邊趨勢盤(會逆勢做多 / 做空被擠爆)
⚠️ 風險:趨勢市場連續觸發逆勢訊號可能虧損嚴重。建議搭配每日下單上限。
① Pine Script 源碼(貼到 TradingView Pine Editor)
//@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)
② TVSBot webhook payload(貼到 TV Alert 的 Message 欄)
{
  "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 模板按鈕拿),以及 exchangesymbol(你綁定的交易所)

EMA 黃金/死亡交叉

新手永續合約

短期 EMA 上穿長期 EMA = 黃金交叉做多;下穿 = 死亡交叉做空。趨勢追蹤經典款,缺點是震盪盤會被「假突破」連續打臉。建議用較長週期(如 4h / 1d)+ 止損。

✓ 適合
趨勢明確的中長線(4h - 日線級別)
✗ 不適合
震盪盤、短線 1m-15m(會被反覆鋸齒洗倉)
⚠️ 風險:趨勢反轉時延遲明顯。記得 set TP/SL 防止單邊回吐獲利。
① Pine Script 源碼(貼到 TradingView Pine Editor)
//@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)
② TVSBot webhook payload(貼到 TV Alert 的 Message 欄)
{
  "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 模板按鈕拿),以及 exchangesymbol(你綁定的交易所)

布林帶觸碰回彈

中等現貨

價格觸碰布林帶下軌且 RSI 仍 < 50 視為超賣 → buy;觸碰上軌且 RSI > 50 → sell。比純 RSI 更嚴格(要兩個條件同時成立)。

✓ 適合
高波動但仍在 trading range 內的資產(如 BTC / ETH 主流幣震盪期)
✗ 不適合
強趨勢 + 帶突破(會在帶外持續運行)
⚠️ 風險:突破行情下會在錯誤方向連續觸發。建議 sl_pct 設緊一點(1-2%)。
① Pine Script 源碼(貼到 TradingView Pine Editor)
//@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)
② TVSBot webhook payload(貼到 TV Alert 的 Message 欄)
{
  "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 模板按鈕拿),以及 exchangesymbol(你綁定的交易所)

SuperTrend 趨勢跟蹤

中等永續合約

SuperTrend 翻多 → buy;翻空 → sell。比 EMA cross 反應更快,止損也內建(基於 ATR)。趨勢盤的主力選手。

✓ 適合
高波動有明確方向的市場(突破 / 趨勢)
✗ 不適合
區間整理、橫盤(容易被甩出)
⚠️ 風險:ATR 倍數設太小會頻繁翻轉造成 over-trading。新手建議 multiplier=3 起跳。
① Pine Script 源碼(貼到 TradingView Pine Editor)
//@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)
② TVSBot webhook payload(貼到 TV Alert 的 Message 欄)
{
  "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 模板按鈕拿),以及 exchangesymbol(你綁定的交易所)

成交量突破

進階永續合約

收盤價突破 N 根 K 的最高點 + 成交量 > 平均成交量 1.5 倍 → buy;跌破最低點 + 量爆 → sell。捕捉大行情的進場時機。

✓ 適合
突破型 trader、想抓主行情啟動點
✗ 不適合
假突破多的市場、低流動性山寨幣
⚠️ 風險:假突破會嚴重打臉。建議搭配 reverse_mode 一鍵翻轉觀察兩面表現。
① Pine Script 源碼(貼到 TradingView Pine Editor)
//@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)
② TVSBot webhook payload(貼到 TV Alert 的 Message 欄)
{
  "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 模板按鈕拿),以及 exchangesymbol(你綁定的交易所)

DCA 階梯式進場(被動定投)

新手現貨

每跌 N% 自動加倉。不做空、不停損 — 純 averaging down 平攤成本。適合長期看好但短線怕抓底失敗的用戶。**用 margin / leverage 跑這個會 100% 爆倉,請只用現貨。**

✓ 適合
長線看多、不擔心短期波動的優質資產(BTC / ETH / 大盤 ETF)
✗ 不適合
山寨幣(可能跌成 0)、合約(會爆倉)
⚠️ 風險:需要充足資金準備持續加倉。一定要設 max_daily_orders 避免極端行情無限買入。
① Pine Script 源碼(貼到 TradingView Pine Editor)
//@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)
② TVSBot webhook payload(貼到 TV Alert 的 Message 欄)
{
  "secret": "<你的 webhook_secret>",
  "strategy": "dca-grid",
  "side": "buy",
  "symbol": "BTCUSDT",
  "exchange": "binance",
  "market_type": "spot",
  "qty_type": "usdt",
  "qty": 100
}

ⓘ 記得改 secret(你的 webhook_secret,從策略 TV 模板按鈕拿),以及 exchangesymbol(你綁定的交易所)

準備好把策略接到自動下單?

把 Pine 貼到 TradingView、Alert 設好,TVSBot 來處理執行。

開始註冊 →