Strategy Lab
Algorithmic Backtester & Overfitting Tool
Compose entry and exit rules, generate matching Python, and run them against real provider OHLC with execution costs.
Optimization Controls
Multi-condition rule matrix
Yahoo H1 limit: 725 calendar days. Earlier dates are disabled.
Resolved: 2024-08-07 → 2026-08-02 (2Y)
Entry Condition Matrix
Rule 1
Rule 2
Reward : Risk = 2.00 : 1
Positive swap earns interest; negative swap pays it. Wednesday rollover is charged/credited triple.
Execution Script Preview
backtesting.py template · regenerated live from the rule matrix
# ============================================================# ApexTrading auto-generated strategy · backtesting.py template# Asset: EUR/USD | Timeframe: H1# Horizon: 2024-08-07 → 2026-08-02 (2Y)# Risk: SL 1.5% / TP 3%# ============================================================import yfinance as yffrom backtesting import Backtest, Strategyfrom backtesting.lib import crossoverimport talib # Historical OHLCV pulled from the free yfinance asset layer.data = yf.download("EURUSD=X", start="2024-08-07", end="2026-08-02", interval="1h") class ApexStrategy(Strategy): stop_loss_pct = 0.0150 take_profit_pct = 0.0300 pip_size = 0.0001 trailing_stop_pct = 0.0100 breakeven_trigger_pips = 20 long_swap_pips = -0.5 short_swap_pips = -0.5 def init(self): close = self.data.Close self.last_rollover_date = None self.e1a = self.I(talib.EMA, close, 21) self.e1b = self.I(talib.SMA, close, 50) self.e2a = self.I(talib.RSI, close, 14) def next(self): price = self.data.Close[-1] current_date = self.data.index[-1].date() if self.position and self.last_rollover_date and current_date > self.last_rollover_date: multiplier = 3 if current_date.weekday() == 2 else 1 swap_pips = self.long_swap_pips if self.position.is_long else self.short_swap_pips lots = abs(self.position.size) / 100_000 pip_value = 10 if "EUR/USD".endswith("/USD") else self.pip_size / price * 100_000 self._broker._cash += swap_pips * pip_value * lots * multiplier self.last_rollover_date = current_date if self.position: entry = self.position.entry_price pnl_pct = (price - entry) / entry * 1 if pnl_pct <= -self.stop_loss_pct: self.position.close() return if pnl_pct >= self.take_profit_pct: self.position.close() return entry_signal = (crossover(self.e1a, self.e1b)) and (self.e2a[-1] < 70) if entry_signal and not self.position: sl_price = price * (1 - self.stop_loss_pct) tp_price = price * (1 + self.take_profit_pct) size_units = max(1, (self.equity * 0.01) / (price * self.stop_loss_pct)) self.buy(size=round(size_units), sl=sl_price, tp=tp_price) bt = Backtest(data, ApexStrategy, cash=100_000, commission=0.000300)stats = bt.run()print(stats) No backtest has been run
Configure the strategy, risk controls, and historical range, then run the backtest to populate performance metrics, robustness analysis, the equity curve, and regime attribution.