STRATEGY Strategy · Updated April 2026 · ~5 min · For TradingView desktop 3.2.1

Write a Bitcoin EMA Cross Strategy in Pine Script and Backtest It

Pine Script Bitcoin strategy illustration

Turning "I feel this makes money" into "the data says so" takes one snippet of Pine Script. This BTC EMA-cross strategy runs as-is.

Open the Pine editor and paste

//@version=6
strategy("BTC EMA Cross", 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("Long", strategy.long)
if ta.crossunder(fast, slow)
    strategy.close("Long")

plot(fast, color = color.purple)
plot(slow, color = color.gray)

Switch to BTCUSD daily, click Add to chart, and the Strategy Tester auto-generates a report and marks each trade.

Read four numbers first

  1. Max drawdown: look at it before net profit — crypto drawdowns routinely exceed 50%; if you can't stomach it you can't run it;
  2. Payoff × win rate: only the product is the expectancy;
  3. Number of trades: under 100 has no statistical meaning;
  4. Fees: crypto fees and slippage aren't small — fill them honestly.
Don't overfit: if a small parameter change swings performance, or it only shines on one stretch, that's overfitting. Tune on one span and validate on another — see grid backtesting and DCA backtesting.