STRATEGY 策略回测 · 更新于 2026 年 4 月 · 约 3 分钟 · TradingView 桌面版 3.2.1 适用

用 Pine Script 写一个比特币均线交叉策略并回测

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 日线,点添加到图表,底部策略测试器会自动生成回测报告并在图上标出每笔进出场。

报告先看四个数

  1. 最大回撤:先看它而非净利——加密回撤动辄 50%+,扛不住就用不了;
  2. 盈亏比 × 胜率:相乘才是期望;
  3. 交易次数:少于 100 笔没有统计意义;
  4. 手续费:加密手续费与滑点不小,如实填。
别过拟合:参数改一点绩效就大变、只在某段行情神奇,都是过拟合信号。用一段数据调参、另一段验证,见网格策略回测DCA 回测