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.
Fractal Breakout uses Bill Williams' fractal pattern — a bar with two lower highs on each side. Enters long when price closes above a confirmed fractal high, exits when price falls to a fractal low.
class FractalBreakout(Strategy):
left = 2; right = 2
def init(self):
n = self.left + self.right + 1
h, l = pd.Series(self.data.High), pd.Series(self.data.Low)
fh = h.rolling(n, center=True).apply(lambda x: x.iloc[self.left] if x.iloc[self.left]==x.max() else np.nan, raw=False)
fl = l.rolling(n, center=True).apply(lambda x: x.iloc[self.left] if x.iloc[self.left]==x.min() else np.nan, raw=False)
self.fh = self.I(lambda: fh, name="FractalHigh")
self.fl = self.I(lambda: fl, name="FractalLow")
def next(self):
idx = self.left + self.right + 2
fh_val = self.fh[-idx]; fl_val = self.fl[-idx]
if not np.isnan(fh_val) and self.data.Close[-1] >= fh_val and not self.position: self.buy()
elif not np.isnan(fl_val) and self.data.Close[-1] <= fl_val and self.position: self.position.close()