STRATEGY 策略回測 · 更新於 2026 年 4 月 · 約 3 分鐘 · TradingView 桌面版 3.2.1 適用
用 Pine Script 寫一個比特幣均線交叉策略並回測
把"感覺能賺"變成"資料說話",只需一段 Pine Script。下面這個 BTC 均線交叉策略可直接照抄執行。
開啟 Pine 編輯器,貼上
//@version=6
strategy("BTC EMA 交叉", overlay = true,
initial_capital = 10000,
default_qty_type = strategy.percent_of_equity,
default_qty_value = 20)
fast = ta.ema(close, 21)
slow = ta.ema(close, 55)
if ta.crossover(fast, slow)
strategy.entry("多", strategy.long)
if ta.crossunder(fast, slow)
strategy.close("多")
plot(fast, color = color.purple)
plot(slow, color = color.gray)
切到 BTCUSD 日線,點新增到圖表,底部策略測試器會自動生成回測報告並在圖上標出每筆進出場。
報告先看四個數
- 最大回撤:先看它而非淨利——加密回撤動輒 50%+,扛不住就用不了;
- 盈虧比 × 勝率:相乘才是期望;
- 交易次數:少於 100 筆沒有統計意義;
- 手續費:加密手續費與滑點不小,如實填。