← Back to Home
EMA Cross Strategy Backtest AMZN 19.99% Return With 7.38% Max Drawdown

EMA Cross Strategy Backtest AMZN 19.99% Return With 7.38% Max Drawdown

Get the full strategy library: This article uses one strategy from the Mega Backtrader Strategy Pack, a package of 500+ Backtrader-ready Python trading strategies with batch backtesting, dashboards, metrics, charts, and documentation.

Download the package here: Mega Backtrader Strategy Pack

If you want to test complete Backtrader strategies without building every idea from scratch, the package gives you strategy code, batch runners, metrics, charts, and publishable reports in one workflow.

This article walks through EmaCrossStrategy, one of the strategies included in the Mega Backtrader Strategy Pack. The strategy was tested on AMZN daily candles from 2025-06-20 to 2026-06-18, with SPY used as the benchmark.

The headline result is 19.99% Return With 7.38% Max Drawdown.

Result Value
Strategy return 19.99%
AMZN buy-and-hold return 16.55%
SPY benchmark return 25.65%
Excess return vs asset 3.45%
Sharpe ratio 1.31
Max drawdown 7.38%
Closed trades 5
Open trades 0
Win rate 40.00%

Strategy Idea

The strategy uses a fast EMA and slow EMA crossover, then manages exits with both opposite crossover signals and a trailing stop.

The logic can be summarized as:

  1. Calculate fast and slow exponential moving averages.
  2. Use a Backtrader CrossOver indicator to detect turns.
  3. Enter when the fast EMA crosses above the slow EMA.
  4. Exit when the opposite crossover appears or the trailing stop is hit.
  5. Use most available cash for position sizing in the original strategy code.

The package batch run used the default long-only execution mode, so short-style sell calls are handled as exits unless shorting is explicitly enabled.

Code Walkthrough

The crossover is built from a 7-period and 30-period EMA:

self.ema_fast = bt.indicators.EMA(self.data_close, period=self.params.fast_ema)
self.ema_slow = bt.indicators.EMA(self.data_close, period=self.params.slow_ema)
self.crossover = bt.indicators.CrossOver(self.ema_fast, self.ema_slow)

A bullish crossover creates the long signal:

if self.crossover > 0:
    cash = self.broker.get_cash()
    size = (cash * self.params.order_percentage) / current_price
    self.order = self.buy(size=size)

The trailing stop follows the highest price after entry:

trailing_stop_price = self.highest_price * (1 - self.params.trailing_stop_pct)
if current_price <= trailing_stop_price:
    self.order = self.sell(size=self.position.size)

The important point is that the strategy is a complete Backtrader class, not just a loose signal snippet. It defines indicators, position rules, exit behavior, and order handling in one reusable strategy module.

Backtest Setup

Setting Value
Asset AMZN
Benchmark SPY
Period 1y
Data window 2025-06-20 to 2026-06-18
Interval 1d
Starting cash $10,000.00
Final value $11,999.39
Strategy file EmaCrossStrategy.py
Strategy class EmaCrossStrategy

Results

Metric Value
Starting portfolio value $10,000.00
Final portfolio value $11,999.39
Strategy return 19.99%
AMZN buy-and-hold return 16.55%
SPY benchmark return 25.65%
Excess return vs benchmark -5.66%
Excess return vs asset buy-hold 3.45%
Sharpe ratio 1.31
Max drawdown 7.38%
Total trades 5
Closed trades 5
Open trades 0
Winning trades 2
Losing trades 3
Win rate 40.00%
Runtime 3.39 seconds

This run ended with 0 open trade(s). Closed-trade statistics are based on completed trades, while final portfolio value is the account value at the final bar.

Equity Curve vs Benchmark

EmaCrossStrategy AMZN equity curve versus benchmark

The equity curve shows the strategy path from $10,000.00 to $11,999.39.

Drawdown vs Benchmark

EmaCrossStrategy AMZN drawdown versus benchmark

The drawdown chart shows maximum strategy drawdown at 7.38%.

Rolling Return vs Benchmark

EmaCrossStrategy AMZN rolling return versus benchmark

The rolling return chart shows how performance developed across the test window.

Daily Return Distribution

EmaCrossStrategy AMZN daily returns histogram

The daily return distribution excludes zero-return strategy days. In this run, 208 flat strategy-equity days were removed from the histogram, leaving 42 non-zero strategy return days plotted.

What This Shows

This example shows how the Mega Backtrader Strategy Pack can turn a strategy idea into a full research artifact: code, batch execution, metrics, charts, and a publishable write-up.

For strategy research, this matters because one idea is rarely enough. You want to compare trend, momentum, mean reversion, volatility, volume, machine learning, and ensemble approaches across multiple assets and time windows. A large strategy library gives you that workflow immediately.

Get the Complete Strategy Library

EmaCrossStrategy is one of 500+ Backtrader-ready strategies included in the Mega Backtrader Strategy Pack.

Get the full package here: Mega Backtrader Strategy Pack

The package includes:

If you want to test more strategy ideas faster, this package gives you the code and the research workflow.

Get the Mega Backtrader Strategy Pack

Disclaimer

This article is for research and educational use only. Backtest results are not financial advice, investment advice, or a guarantee of future performance. Always validate strategy logic, data quality, execution assumptions, costs, slippage, and risk before using any trading system.