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 all three MAs (short, mid, long) to be in bullish alignment (short > mid > long) before entering. This triple confirmation only fires in strong, established trends. Exits when the short MA drops below the mid.
class TripleMA(Strategy):
n_short = 10
n_mid = 20
n_long = 50
def init(self):
close = self.data.Close
self.ma_s = self.I(_sma, close, self.n_short)
self.ma_m = self.I(_sma, close, self.n_mid)
self.ma_l = self.I(_sma, close, self.n_long)
def next(self):
if self.ma_s[-1] > self.ma_m[-1] > self.ma_l[-1] and not self.position:
self.buy()
elif self.ma_s[-1] < self.ma_m[-1] and self.position:
self.position.close()| Total return | +29.848% |
| Net profit | $298,481 |
| Gross profit | $631,396 |
| Gross loss | $470,119 |
| CAGR | +2.479% |
| Annualized return | +2.479% |
| Monthly average return | +0.226% |
| Median monthly return | -0.990% |
| Best month return | +6.123% |
| Worst month return | -8.306% |
| Rolling 1-month return | +10.752% |
| Return per trade | +0.133 |
| Log return CAGR | -7.672% |
| Compounded vs simple return difference | -35.201% |
16 trades · green dashes = buy entries · red dashes = sell exits
| Total return | +23.122% |
| Net profit | $231,220 |
| Gross profit | $446,610 |
| Gross loss | $216,830 |
| CAGR | +6.455% |
| Annualized return | +6.455% |
| Monthly average return | +0.500% |
| Median monthly return | +3.808% |
| Best month return | +5.489% |
| Worst month return | -5.988% |
| Rolling 1-month return | +10.963% |
| Return per trade | +1.313 |
| Log return CAGR | +19.625% |
| Compounded vs simple return difference | -15.752% |