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.
Breakout strategy using Donchian channels (N-period high/low). Enters long when price closes above the prior N-period high, signalling a breakout. Exits when price falls to the N-period low.
class DonchianBreakout(Strategy):
n = 20
def init(self):
self.dc_high = self.I(_donchian_high, self.data.High, self.n)
self.dc_low = self.I(_donchian_low, self.data.Low, self.n)
def next(self):
if self.data.Close[-1] >= self.dc_high[-2] and not self.position:
self.buy()
elif self.data.Close[-1] <= self.dc_low[-2] and self.position:
self.position.close()