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 DemaCrossStrategy, one of the
strategies included in the Mega Backtrader Strategy Pack. The strategy
was tested on TSLA daily candles from 2025-06-20 to
2026-06-18, with SPY used as the
benchmark.
The headline result is 20.98% Return With 60% Win Rate.
| Result | Value |
|---|---|
| Strategy return | 20.98% |
| TSLA buy-and-hold return | 24.31% |
| SPY benchmark return | 25.65% |
| Excess return vs asset | -3.34% |
| Sharpe ratio | 0.93 |
| Max drawdown | 17.37% |
| Closed trades | 5 |
| Open trades | 0 |
| Win rate | 60.00% |
The strategy uses double exponential moving averages to reduce lag versus ordinary moving averages, then trades fast-versus-slow DEMA crossovers.
The logic can be summarized as:
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.
The two DEMA lines define the trading signal:
self.dema_fast = bt.indicators.DEMA(self.data_close, period=self.params.fast_dema)
self.dema_slow = bt.indicators.DEMA(self.data_close, period=self.params.slow_dema)
self.crossover = bt.indicators.CrossOver(self.dema_fast, self.dema_slow)A bullish crossover creates a long setup:
if self.crossover > 0:
cash = self.broker.get_cash()
size = (cash * self.params.order_percentage) / self.data_close[0]
self.order = self.buy(size=size)The long exit is the opposite crossover:
elif self.position.size > 0:
if self.crossover < 0:
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.
| Setting | Value |
|---|---|
| Asset | TSLA |
| Benchmark | SPY |
| Period | 1y |
| Data window | 2025-06-20 to 2026-06-18 |
| Interval | 1d |
| Starting cash | $10,000.00 |
| Final value | $12,097.54 |
| Strategy file | DemaCrossStrategy.py |
| Strategy class | DemaCrossStrategy |
| Metric | Value |
|---|---|
| Starting portfolio value | $10,000.00 |
| Final portfolio value | $12,097.54 |
| Strategy return | 20.98% |
| TSLA buy-and-hold return | 24.31% |
| SPY benchmark return | 25.65% |
| Excess return vs benchmark | -4.68% |
| Excess return vs asset buy-hold | -3.34% |
| Sharpe ratio | 0.93 |
| Max drawdown | 17.37% |
| Total trades | 5 |
| Closed trades | 5 |
| Open trades | 0 |
| Winning trades | 3 |
| Losing trades | 2 |
| Win rate | 60.00% |
| Runtime | 3.30 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.
The equity curve shows the strategy path from $10,000.00 to $12,097.54.
The drawdown chart shows maximum strategy drawdown at 17.37%.
The rolling return chart shows how performance developed across the test window.
The daily return distribution excludes zero-return strategy days. In this run, 165 flat strategy-equity days were removed from the histogram, leaving 85 non-zero strategy return days plotted.
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.
DemaCrossStrategy 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:
strategies/
package.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
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.