Strategy example
EMA crossover Pine Script v6 backtest example.
Use a simple Pine Script v6 EMA crossover strategy to learn the GPT backtesting workflow, cost settings, and result-review checklist.
What the strategy tests
This long-only example enters when a 20-period exponential moving average crosses above a 50-period EMA. It closes the position when the fast EMA crosses back below the slow EMA. The example intentionally uses one timeframe, one entry ID, and a full-position exit.
Pine Script v6 code
//@version=6
strategy(
"EMA Crossover Example",
overlay = true,
pyramiding = 0,
commission_type = strategy.commission.percent,
commission_value = 0.10,
calc_on_every_tick = false,
calc_on_order_fills = false,
process_orders_on_close = false,
use_bar_magnifier = false,
fill_orders_on_standard_ohlc = false
)
fastLength = input.int(20, "Fast EMA")
slowLength = input.int(50, "Slow EMA")
fast = ta.ema(close, fastLength)
slow = ta.ema(close, slowLength)
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
strategy.close("Long")
plot(fast, color=color.blue)
plot(slow, color=color.orange)Educational example only. It is not a recommendation to trade this strategy or any market.
Example GPT request
Backtest this EMA crossover strategy on CRYPTO:BTCUSD using daily bars from 2021-01-01 through 2024-12-31. Use $10,000 initial capital, 0.10% commission, two ticks of slippage, and keep the default EMA inputs. Show maximum drawdown and the completed trade history.
✓ Verified against the public dataset catalog · July 13, 2026
What to inspect after the run
- Whether the date range includes trending and sideways conditions
- Maximum drawdown relative to the net return
- The number of trades and average holding period
- How commission and slippage change the result
- Performance on a later validation period that was not used to choose 20 and 50