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 the N-period price channel (highest high / lowest low). Enters long on a close above the prior channel high, exits on a close below the channel low. Similar to Donchian but uses raw high/low.
class PriceChannel(Strategy):
n = 20
def init(self):
self.ch_high = self.I(_channel_high, self.data.High, self.n)
self.ch_low = self.I(_channel_low, self.data.Low, self.n)
def next(self):
if self.data.Close[-1] >= self.ch_high[-2] and not self.position:
self.buy()
elif self.data.Close[-1] <= self.ch_low[-2] and self.position:
self.position.close()