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.
Keltner Squeeze detects when Bollinger Bands contract inside Keltner Channels (low volatility squeeze). Enters long on a breakout above the upper Keltner band, exits when price falls back below the EMA.
class KeltnerSqueeze(Strategy):
bb_n = 20; kelt_n = 20; atr_n = 10; mult = 2
def init(self):
atr = _atr(self.data.High, self.data.Low, self.data.Close, self.atr_n)
self.kelt_upper = self.I(lambda: _ema(self.data.Close, self.kelt_n) + self.mult * atr, name="KeltUpper")
self.sma = self.I(_sma, self.data.Close, self.kelt_n)
def next(self):
if self.data.Close[-1] > self.kelt_upper[-2] and not self.position: self.buy()
elif self.data.Close[-1] < self.sma[-1] and self.position: self.position.close()| Total return | +31.822% |
| Net profit | $318,224 |
| Gross profit | $585,515 |
| Gross loss | $406,250 |
| CAGR | +2.975% |
| Annualized return | +2.975% |
| Monthly average return | +0.267% |
| Median monthly return | -0.547% |
| Best month return | +7.923% |
| Worst month return | -5.800% |
| Rolling 1-month return | +13.578% |
| Return per trade | +0.256 |
| Log return CAGR | +30.919% |
| Compounded vs simple return difference | -27.353% |
17 trades · green dashes = buy entries · red dashes = sell exits
| Total return | -1.067% |
| Net profit | -$10,670 |
| Gross profit | $187,870 |
| Gross loss | $190,650 |
| CAGR | -0.322% |
| Annualized return | -0.322% |
| Monthly average return | +0.003% |
| Median monthly return | -1.514% |
| Best month return | +4.631% |
| Worst month return | -4.101% |
| Rolling 1-month return | +6.095% |
| Return per trade | -0.063 |
| Log return CAGR | -2.295% |
| Compounded vs simple return difference | +0.150% |