Strategy
This strategy is backtested on daily OHLCV price data across major US equity indices and ETFs. Entry and exit signals are generated from the strategy's indicators with no lookahead bias — trades execute at the open of the bar following the signal.
Performance metrics are computed per symbol and shown individually. The parameter optimization section (where available) runs a grid search over the strategy's key parameters, optimizing for Sharpe ratio. Transaction costs and slippage are not modeled.
The signal logic and indicator code for this strategy is shown in the methodology code section below.
Generates a buy signal when the fast SMA crosses above the slow SMA, and exits when the slow SMA crosses back above the fast. Captures sustained directional moves by filtering out short-term noise through two smoothed price averages.
class SmaCross(Strategy):
n_fast = 10
n_slow = 20
def init(self):
close = self.data.Close
self.sma_fast = self.I(_sma, close, self.n_fast)
self.sma_slow = self.I(_sma, close, self.n_slow)
def next(self):
if crossover(self.sma_fast, self.sma_slow):
self.buy()
elif crossover(self.sma_slow, self.sma_fast):
self.position.close()| Total return | +12.910% |
| Net profit | $129,098 |
| Gross profit | $536,786 |
| Gross loss | $417,148 |
| CAGR | +1.836% |
| Annualized return | +1.836% |
| Monthly average return | +0.192% |
| Median monthly return | +0.775% |
| Best month return | +10.107% |
| Worst month return | -9.487% |
| Rolling 1-month return | +15.752% |
| Return per trade | +0.341 |
| Log return CAGR | +29.535% |
| Compounded vs simple return difference | -8.909% |
18 trades · green dashes = buy entries · red dashes = sell exits
| Total return | +13.144% |
| Net profit | $131,440 |
| Gross profit | $490,020 |
| Gross loss | $339,940 |
| CAGR | +3.783% |
| Annualized return | +3.783% |
| Monthly average return | +0.339% |
| Median monthly return | +3.319% |
| Best month return | +10.982% |
| Worst month return | -8.855% |
| Rolling 1-month return | +17.369% |
| Return per trade | +0.690 |
| Log return CAGR | +27.375% |
| Compounded vs simple return difference | -3.066% |