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.
Requires price to be above both a short and long moving average before entering. This dual confirmation reduces false signals in sideways markets. Exits when price drops below the short MA.
class DualMA(Strategy):
n_short = 20
n_long = 50
def init(self):
close = self.data.Close
self.ma_short = self.I(_sma, close, self.n_short)
self.ma_long = self.I(_sma, close, self.n_long)
def next(self):
if self.data.Close[-1] > self.ma_short[-1] and self.data.Close[-1] > self.ma_long[-1]:
if not self.position:
self.buy()
elif self.data.Close[-1] < self.ma_short[-1] and self.position:
self.position.close()| Total return | +63.509% |
| Net profit | $635,095 |
| Gross profit | $845,554 |
| Gross loss | $613,105 |
| CAGR | +4.228% |
| Annualized return | +4.228% |
| Monthly average return | +0.359% |
| Median monthly return | -1.538% |
| Best month return | +6.054% |
| Worst month return | -8.451% |
| Rolling 1-month return | +13.490% |
| Return per trade | +0.232 |
| Log return CAGR | +0.529% |
| Compounded vs simple return difference | -66.979% |
36 trades · green dashes = buy entries · red dashes = sell exits
| Total return | +27.116% |
| Net profit | $271,160 |
| Gross profit | $644,640 |
| Gross loss | $371,170 |
| CAGR | +7.482% |
| Annualized return | +7.482% |
| Monthly average return | +0.639% |
| Median monthly return | -3.005% |
| Best month return | +2.184% |
| Worst month return | -8.225% |
| Rolling 1-month return | +6.168% |
| Return per trade | +0.671 |
| Log return CAGR | -13.357% |
| Compounded vs simple return difference | -32.647% |